Solved

Crashing with IDispatch Invoke

Posted on 2002-06-06
1
547 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:_maverick_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
BeyondWu earned 150 total points
ID: 7061211
If the method of Close has no parameter, use following code.

DISPPARAMS param = {NULL, NULL, 0, 0};
//run the close method
HRESULT hr = myDispatch->Invoke(
   dispid ,
   IID_NULL,
   LOCALE_USER_DEFAULT,
   DISPATCH_METHOD,
   &param, // <--- shouldn't be NULL!
   &result,
   &except,
   &argerr);
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question