RESOLUTION
To work around this problem, you can call the
GetIDsOfNames function or implement a dual interface to call a COM object that is implemented in Java.
Call the GetIDsOfNames Function
Call the
GetIDsOfNames function. For languages that do not automatically call
GetIDsOfNames, such as Visual C++, you must call the function yourself.
GetIDsOfNames queries the COM object for the DISPIDs for one or more method names.
GetIDsOfNames takes the following parameters:
REFIID riid Must be IID_NULL
OLECHAR FAR* FAR* rgszNames Array of names to be mapped
unsigned int cNames Number of names to be mapped
LCID lcid Locale
DISPID FAR* rgDispId Caller allocated array of DISPIDs
The first parameter is an array of names to be mapped. The first name must be the name of a method; all other names are for parameters to the named method. The following sample code illustrates how to call
GetIDsOfNames:
HRESULT hresult;
IDispatch FAR* pdisp = (IDispatch FAR*)NULL;
DISPID dispid;
OLECHAR FAR* szMember = "color";
// Code that sets a pointer to the dispatch (pdisp) is omitted.
hresult = pdisp->GetIDsOfNames(IID_NULL,&szMember,1, LOCALE_SYSTEM_DEFAULT,&dispid);
After you have the DISPIDs, you can call
IDispatch->Invoke to call a particular method.
Invoke takes the following parameters:
DISPID dispIdMember DISPID of method to be called
REFIID riid Must be IID_NULL
LCID lcid Locale
WORD wFlags Flag that specifies the type of call
DISPPARAMS FAR* pDispParams Array of DISPPARAMs that contain
parameters to method
VARIANT FAR* pVarResult Location for storage of return value
EXCEPINFO FAR* pExcepInfo Exception info structure or NULL
unsigned int FAR* puArgErg Index of error in param array
The sample code appears as follows:
int nArgErr;
pdisp->Invoke(szMember, IID_NULL, LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD, NULL, NULL, &nArgErr);
Implement a Dual Interface
You can implement your COM object with a dual interface so that when you call an application, you bypass the Auto-IDispatch mechanism altogether. To do this, write an .idl file and compile it into a type library. Then, in the Microsoft Visual J++ project settings, click
Use existing type library, and specify your typelib.