Solved

Crashing with IDispatch Invoke

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 74
Named range not carried over 10 57
EvenOdd challenge 10 83
wordappend challenge 8 85
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video discusses moving either the default database or any database to a new volume.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now