Link to home
Start Free TrialLog in
Avatar of _maverick_
_maverick_

asked on

Crashing with IDispatch Invoke

I can't figure out why this code keeps crashing.  I am trying to invoke methods and properties in the documents collection using the IDispatch pointer returned by the GetDocuments in the application object.  The application I am trying to work with here is FileMaker


//create application interface
IFMIAppn* m_pFmApp;
m_pFmApp = new IFMIAppn;
m_pFmApp->CreateDispatch(_T("FMPRO.Application"));


//the method we want to run in the documents collection is Close
IDispatch* myDispatch;
DISPID dispid;
OLECHAR* szName = OLESTR("Close");

//get IDispatch to document collection for application...the variant holds IDispatch
VARIANT myVar = m_pFmApp->GetDocuments();

myDispatch = myVar.pdispVal;

//get DISPID to the close method
myDispatch->GetIDsOfNames(IID_NULL, &szName, 1, ::GetUserDefaultLCID(), &dispid);

//everything works fine at this point...getIDsOfname works ok its 0x5
if(dispid == 0x5)
{ AfxMessageBox("DISPID for method Close is 0x5");  }

//needed for Invoke
EXCEPINFO  except;
unsigned   int argerr;
VARIANT result;

//run the close method
HRESULT hr = myDispatch->Invoke(
    dispid ,
    IID_NULL,
    LOCALE_USER_DEFAULT,
    DISPATCH_METHOD,
    NULL,
    &result,
    &except,
    &argerr);


As soon as I run the myDispatch->Invoice my application crashes with an error message:

"The instruction at "0x779b5114" reference memory at "0x000000000".  The memory could not be "read"

Thanks for any help
ASKER CERTIFIED SOLUTION
Avatar of BeyondWu
BeyondWu
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial