Solved

Crashing with IDispatch Invoke

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 73
centeredAverage challenge 8 179
no14 challenge 14 70
zeroMAx challenge 20 111
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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