tags:

views:

427

answers:

4

What would the equivalent in C/C++?

+10  A: 

It's the CoCreateInstance() function.

It is convenient to use CoCreateInstance when you need to create only a single instance of an object on the local machine. If you are creating an instance on remote computer, call CoCreateInstanceEx. When you are creating multiple instances, it is more efficient to obtain a pointer to the class object's IClassFactory interface and use its methods as needed. In the latter case, you should use the CoGetClassObject function.

You'll need to #include <Objbase.h> and you'll need to link to ole32.lib

VoidPointer
+4  A: 

Just two calls. You need CLSIDFromProgID() to map the argument you normally pass to CreateObject to a CLSID. Which you can then use in CoCreateInstance().

Hans Passant
+4  A: 

Do not forget to call CoInitializeEx or CoInitialize before CoCreateInstance

Yaroslav
A: 

hi, i have the same problem, have you found the solution already?

i have a CCW wrapper for my .Net class, i can create instance using CreateIntance(progid) in VB6. how will i do it in C++?

CoInitialize(NULL);
MyServiceClient::_ServiceClient *com_ptr;
MyServiceClient::_ServiceClientPtr p(__uuidof(MyServiceClient::_ServiceClient));

com_ptr = p;
com_ptr->TestHello("asd");

but i always get error when trying to invoke a method in my CCW.