=?windows-1252?Q?Calling_Late_Binding_COM_functions=85_Part_3?=
Hi everybody, Sven and Alf
This is the continuation of the topic I've started earlier:
http://groups.google.ca/group/microsoft.public.vc.mfc/browse_frm/thread/1626=
fb4121ba96e3/dec19558d0389a91?hl=en&lnk=gst&q=Calling+COM+functions+us=
ing+IDispatch-%3EInvoke#dec19558d0389a91
By the way all codes provided by Sven and Alf are working OK, the
problem was
with this this COM initialization, wich was this COM providers fault,
now the very first method =93Start=94 works Ok.
But here is the new issue. The very next method must return the
pointer to another interface. Here is the prototype of the function
which I got from OleView:
HRESULT NewObject( [in] BSTR ClassName,
[in, optional] VARIANT Param1,
[in, optional] VARIANT Param2,
[out, retval] IDispatch** Value);
Two optional parameters mean nothing, what matters only ClassName.
So I've tried to use generic approach:
DISPID dispid;
OLECHAR FAR* szMemberName = L"NewObject";
HRESULT hr = pIDispatch->GetIDsOfNames(IID_NULL,
&szMemberName, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
if( SUCCEEDED(hr) )
{
VARIANT varResult;
DISPID dispidNamed = DISPATCH_METHOD;
EXCEPINFO excep;
UINT uArgErr;
DISPPARAMS dispparams;
dispparams.cNamedArgs = 0;
dispparams.cArgs = 4;
dispparams.rgdispidNamedArgs = NULL;
IDispatch* pOSS = NULL;
dispparams.rgvarg = new VARIANTARG[4];
dispparams.rgvarg[0].vt = VT_DISPATCH;
dispparams.rgvarg[0].pdispVal = pOSS;
dispparams.rgvarg[1].vt = VT_ERROR;
dispparams.rgvarg[1].lVal = DISP_E_PARAMNOTFOUND;
dispparams.rgvarg[2].vt = VT_ERROR;
dispparams.rgvarg[2].lVal = DISP_E_PARAMNOTFOUND;
dispparams.rgvarg[3].vt = VT_BSTR;
dispparams.rgvarg[3].bstrVal = SysAllocString(L"SomeClassName");
hr = pIDispatch->Invoke( dispid,
IID_NULL,
LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
&dispparams,
&varResult,
&excep,
&uArgErr
);
It fails
I've tried to use Alf's OleAutomationObject class adding another set
param method
void setDispatchParam( size_t i, IDispatch* pDsp )
{
_variant_t v;
v.vt = VT_DISPATCH;
v.pdispVal = pDsp;
myArgValues.at( (myArgValues.size() - 1) - i ) = v.Detach();
}
It didn't work either.
So basically my question is =96 how to setup this
DISPPARAMS structure which must be passed to Invoke,
So it will return pointer to IDispatch?
Thanks in advance,
Alex