Solved

Crashing with IDispatch Invoke

Posted on 2002-06-06
1
543 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_
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 92
Best tools for Backup and restore of Wordpress site 6 58
post4 challenge 28 113
EvenOdd challenge 10 147
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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