Error retrieving Name property from doc with embedded controls

M

mjoe

I am unable to retrieve the Name, Path, or FullName properties
from a Word Document object with a COM Addin written in C++.

Using an ATL application, when trying to retrieve the above
properties from the document object passed to the DocumentChange
event, I get error code 0x800adf21 or 0x800a8029.

To reproduce this, use any document with a Checkbox control
embedded in the document. The error only occurs when dealing
with documents with this control on them.

This also only happens with a C++ written addin. If I do the same
exact thing with a VB addin, it works like a charm.

Also, the property retrieval works fine later -- only on the
document passed during DocumentChange does it fail.

Any ideas why this would be? Any workarounds?

-M-
 
K

Kendal Ferner [MS]

Marion,

You wrote...

"when trying to retrieve the above
properties from the document object passed to the DocumentChange
event, I get error code 0x800adf21 or 0x800a8029"

The DocumentChange event does not have any parameters. Is this a
misstatment or is your signature for the event wrong?

' Typelib
[id(0x00000003), helpcontext(0x00061a83)] void DocumentChange();

' VB event handler
Private Sub appWord_DocumentChange()
End Sub

Also, I'm not having a problem with what you have described. Here is a
sample of how I am accessing the Name, FullName and Path of the document
object. I am retrieving the document object from the ActiveDocument
property of the _Application object. Are you doing anything different from
this? (NOTE: The AutoWrap() function just wraps the GetIDsOfNames() and
Invoke() calls to the IDispatch interface.)

HRESULT hr;


VARIANT vtDocuments = {0};
VariantInit(&vtDocuments);
hr = AutoWrap(DISPATCH_PROPERTYGET, &vtDocuments, m_pApplication,
L"Documents", 0);

VARIANT vtCount = {0};
VariantInit(&vtCount);
hr = AutoWrap(DISPATCH_PROPERTYGET, &vtCount, vtDocuments.pdispVal,
L"Count", 0);

if ( vtCount.lVal > 0 )
{
VARIANT vtActiveDoc = {0};
VariantInit(&vtActiveDoc);
hr = AutoWrap(DISPATCH_PROPERTYGET, &vtActiveDoc, m_pApplication,
L"ActiveDocument", 0);

VARIANT vtName = {0};
VariantInit(&vtName);
hr = AutoWrap(DISPATCH_PROPERTYGET, &vtName, vtActiveDoc.pdispVal,
L"Name", 0);

VARIANT vtFullName = {0};
VariantInit(&vtFullName);
hr = AutoWrap(DISPATCH_PROPERTYGET, &vtFullName,
vtActiveDoc.pdispVal, L"FullName", 0);

VARIANT vtPath = {0};
VariantInit(&vtPath);
hr = AutoWrap(DISPATCH_PROPERTYGET, &vtPath, vtActiveDoc.pdispVal,
L"Path", 0);

WCHAR buf[200];
swprintf(buf, L"%s\t%s\t%s\n", vtName.bstrVal, vtFullName.bstrVal,
vtPath.bstrVal);
OutputDebugStringW(buf);

VariantClear(&vtName);
VariantClear(&vtFullName);
VariantClear(&vtPath);

VariantClear(&vtActiveDoc);
}

VariantClear(&vtCount);
VariantClear(&vtDocuments);


Kendal Ferner
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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