Late binding in C++ without any typelib ?

M

ML

Hello,

I have an application in C++ (unmanaged). This application is a COM client
and needs to call many COM Servers. The COM servers are built with different
languages like VB 6.0, VB.Net, C#, C++, etc. All the COM server needs to
implement a specific COM class with the same list of methods. The list of
methods is the same (same prototypes, but the code inside each method is
different).

In a C++ application, we have to import the typelib of the COM class to be
able to call any method of this class.

In my case, I have to deal with an indeterminate number of COM Server. So I
can't import all the typelib for each COM Class, because I don't know all of
them.

I would like to import only one typelib since all the COM class in each COM
server are the same (methods with same prototypes).

But, it doesn't work.

I've imported a typelib from a C++ COM server in my C++ COM client.
This is the class generated by Visual Studio :

class Xyz : public COleDispatchDriver
{
public:
void Y()
{
InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

};

The method Y() have the id = 0x1


I've imported the typelib from a C# COM Server in my C++ COM client.
This is the class generated by Visual Studio :

class Xyz : public COleDispatchDriver
{
public:
void Y()
{
InvokeHelper(0x60020000, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

};

The method Y() have the id = 0x60020000. That's why it doesn't work.

I tried to call these COM Servers from a vbscript with late binding, and
it's work ! But, in C++, I think we need the typelib even with the late
binding.

Any ideas or suggestions will be appreciated ?

Thanks
 
E

Ed Dore [MSFT]

Hi ML.

If the servers all implement the same interface, theoretically it would be
possible to use just one helper class. You'd just create a separate instance
of the one helper class calling CreateInstance() to create the specific
object you're interested in.

My initial suspicion based on the "symptoms" you are seeing is that the
dispatch ID's for the server methods are not identical. This means you'll
probably need to use GetIDsOfNames to figure out the dispatch id for the
desired method, and call InvokeHelperV directly on a generic
COleDispatchDriver object.

Sincerely,
Ed Dore [MSFT}

This post is "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top