how to return from IDispatch invoke?
-
hi there.. i am working on a spread sheet control..and need to know if there is any problem with the way i am returning from the Invoke call.. When run this method throws an access violation...any ideas.?? here is the code.. long CControl :: GetObjCellCol(long ObjID) { DISPPARAMS DispParam1; EXCEPINFO excep; UINT nArgErr; DISPID dispidNamed; VARIANT * pResult = NULL; DispParam1.cArgs = 1; //number of arguments DispParam1.cNamedArgs = 0; // named arguments. DispParam1.rgdispidNamedArgs = &dispidNamed; // Dispatch IDs of named arguments. DispParam1.rgvarg = new VARIANTARG(); DispParam1.rgvarg->vt = VT_I4; DispParam1.rgvarg->lVal = ObjID; IImpl::Invoke(DISPID_F1_CellCol, IID_NULL , 0 , NULL, &DispParam1,pResult , &excep, &nArgErr); return pResult->lVal; }
-
hi there.. i am working on a spread sheet control..and need to know if there is any problem with the way i am returning from the Invoke call.. When run this method throws an access violation...any ideas.?? here is the code.. long CControl :: GetObjCellCol(long ObjID) { DISPPARAMS DispParam1; EXCEPINFO excep; UINT nArgErr; DISPID dispidNamed; VARIANT * pResult = NULL; DispParam1.cArgs = 1; //number of arguments DispParam1.cNamedArgs = 0; // named arguments. DispParam1.rgdispidNamedArgs = &dispidNamed; // Dispatch IDs of named arguments. DispParam1.rgvarg = new VARIANTARG(); DispParam1.rgvarg->vt = VT_I4; DispParam1.rgvarg->lVal = ObjID; IImpl::Invoke(DISPID_F1_CellCol, IID_NULL , 0 , NULL, &DispParam1,pResult , &excep, &nArgErr); return pResult->lVal; }
pResult is NULL. You should be passing the address of a valid VARIANT structure, i.e.:
VARIANT vtResult = { 0 };
// ...
IImpl::Invoke(
DISPID_F1_CellCol,
IID_NULL,
0,
NULL,
&DispParam1,
&vtResult,
&excep,
&nArgErr
);return vtResult.lVal;
When the called component comes to fill in the result value, it tries to write through a NULL pointer and causes the access violation. Hope this helps.
-
pResult is NULL. You should be passing the address of a valid VARIANT structure, i.e.:
VARIANT vtResult = { 0 };
// ...
IImpl::Invoke(
DISPID_F1_CellCol,
IID_NULL,
0,
NULL,
&DispParam1,
&vtResult,
&excep,
&nArgErr
);return vtResult.lVal;
When the called component comes to fill in the result value, it tries to write through a NULL pointer and causes the access violation. Hope this helps.
oooooooooops thanks :))