Memory Reference Error while getting DispId for AddShape method

L

Linny

Hi,
I am trying to draw shapes in a document using Word automation with C++
(MS Word 2002).

I get an error message saying
'The instruction at "0x004010b2" referenced memory at "0x00000000"
The memory could not be read.'

This happens when I try to get the dispid for AddShape method of Shapes
object. A snip of the code is pasted below.

................
................
................

// Invoking the Add method on the Documents collection object
// to create a new document in Word
szFunction = OLESTR("Add");
hr = pDispDocs->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT,
&dispid_DocsAdd);
hr = pDispDocs->Invoke(dispid_DocsAdd, IID_NULL,
LOCALE_USER_DEFAULT,DISPATCH_METHOD, &dpNoArgs, &vResult, NULL,
NULL);

// Get IDispatch* for the 'Shapes' object
szFunction = OLESTR("Shapes");
hr = pDispDocs->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT,&dispid_Shapes);
hr = pDispDocs->Invoke(dispid_Shapes, IID_NULL,
LOCALE_USER_DEFAULT,DISPATCH_PROPERTYGET, &dpNoArgs, &vResult,
NULL,NULL);

pDispShape = vResult.pdispVal;
VARIANT vArgsShape[1];
DISPPARAMS dpShape;

vArgsShape [0].vt = VT_I4;
vArgsShape [0].lVal = 1;
dpShape.cArgs = 1;
dpShape.cNamedArgs = 0;
dpShape.rgvarg = vArgsShape;

//Invoking the Add method on the Documents collection object
szFunction = OLESTR("AddShape");

// GETTING ERROR AT THIS STAGE
hr = pDispShape->GetIDsOfNames(IID_NULL, &szFunction,
1,LOCALE_USER_DEFAULT, &dispid_Shapes);


hr = pDispShape->Invoke(dispid_Shapes, IID_NULL,
LOCALE_USER_DEFAULT,DISPATCH_METHOD, &dpShape, &vResult, NULL,
NULL);

................
................
................

Please let me know if this is the right process and what is causing the
error.

Linny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top