I am a new VB programmer. I would Like to know the difference between
CreateObject function and New Keyword.
Please tell me in detail.
Thanks in advance.
Printable View
I am a new VB programmer. I would Like to know the difference between
CreateObject function and New Keyword.
Please tell me in detail.
Thanks in advance.
New forces the compiler to verify the existence of the COM server file, and it binds the object at compile time. This is called early binding. It is faster because the overhead of object creation happens during compile & link.
CreateObject binds the COM server during runtime. The compiler has no idea if the COM server even exists. This is called late binding. This is slower for the creation of the first object in the class than early binding. It is also more error-prone, because the VB program has no way to know if the external COM object exists until the program attempts to create the object.
Suggestion : get and read VB COM by Lewis Thomas
Don't forget that 'New' will use the VB runtime for all marshalling and transactional contexts if the class is in the same VB Project whilst CreateObject will always use SCM for this regardless of class location.
Not strictly true: If you declare (Dim) the objects IUnknown interface (or IDispatch if you have to) and then use CreateObject you will use early binding.Quote:
CreateObject binds the COM server during runtime. The compiler has no idea if the COM server even exists. This is called late binding. This is slower for the creation of the first object in the class than early binding. It is also more error-prone, because the VB program has no way to know if the external COM object exists until the program attempts to create the object.
Create Object is slower because it performs a registry lookup of the ProgId, and then uses the SCM to instantiate the object.
Y: You're correct-- but this guy is new - assume he doesn't know IUknown from IDispatch from a vtable.
ok
Thank You very much.