|
Hallo!
I want create an instance of activeX at runtime and then invoke a method from this.
I create already a instance ( with cocreateinstance(...) and create a control with createcontrol(..)) ,
then i get the disid of the method with GetIDsOfNames(...).
I get the right dispid but if i want invoke this method i get a HRESULT = E_UNEXPECTED .
What do i wrong, please help me and a big thanks in advance.
<br />
......<br />
<br />
static CLSID clsid;
<br />
IDispatch *pInterface = 0;<br />
<br />
CoInitialize(NULL);<br />
<br />
HRESULT hRet = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void**) &pInterface ); <br />
if(hRet!=S_OK) pInterface = 0; <br />
<br />
CString CstrMethod = "CONFIG"; <br />
BSTR BstrMethod = CstrMethod.AllocSysString();<br />
<br />
DISPID dispid; <br />
<br />
hRet = pInterface->GetIDsOfNames(IID_NULL, &BstrMethod, CLSCTX_INPROC_SERVER , LOCALE_SYSTEM_DEFAULT, &dispid); <br />
<br />
if(hRet!=S_OK) MessageBox("It is not possible to get the Id of the method!");<br />
<br />
CWnd m_ControlWrapper;<br />
RECT rct = {0,0,5,50};<br />
<br />
BOOL bStat=FALSE;<br />
bStat= m_ControlWrapper.CreateControl(clsid, "Spectrometer", WS_CHILD, rct, this, 1212, NULL, FALSE, NULL);<br />
<br />
if (bStat == FALSE)<br />
{<br />
::MessageBox (m_hWnd,"Error!!", "Could not place control", MB_OK);<br />
return;<br />
}<br />
<br />
VARIANT varResult;<br />
VariantInit(&varResult);<br />
EXCEPINFO ExceptInfo;<br />
DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };<br />
<br />
hRet = pInterface->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &varResult, &ExceptInfo, NULL);<br />
<br />
CoUninitialize(); <br />
|
|
|
|