1

I have been able to create an instance of SharePoint.OpenDocuments.1 ActiveX Control like so:

CLSID clsid;
HRESULT hResult; 
IDispatch *pWApp;
LPCOLESTR strPid = L"SharePoint.OpenDocuments.1";

CoInitialize(NULL);  
hResult = CLSIDFromProgID(strPid, &clsid);
if(SUCCEEDED(hResult))
    hResult = CoCreateInstance(clsid, NULL, CLSCTX_ALL , IID_IDispatch, (void **)&pWApp);

I have some trouble invoking the "EditDocument" method with a document name. I can't figure out how to invoke or use Variants.

Any code tips?

1
  • 1
    Use the #import directive to avoid having to write late-bound code. That's only easy in a scripting language, definitely not in C++. Commented Aug 4, 2012 at 17:43

2 Answers 2

2

At least if I'm reading the docs correctly, you need a BSTR, which you can create with SysAllocString.

Sign up to request clarification or add additional context in comments.

1 Comment

This is very likely the issue. The difference is that SysAllocString will add a prefix length to the string, while the manual way won't (more precisely, the first two bytes will be treated as length). Even better, use the _bstr_t class that manages the string and calls SysFreeString when needed.
0

If you are using ATL in your C++ project, you can easily create a BSTR string by using the class CComBSTR and pass it as parameter to OpenDocuments.EditDocuments

CComBSTR tempBstr = _T("c:\\myfolder\\myfile.txt");
someObj->SomeMethodThatUsesBSTR(tempBstr);

If you are not using ATL, you can then use the class bstr_t from comutil.h the same way:

bstr_t tempBstr = _T("c:\\myfolder\\myfile.txt");
someObj->SomeMethodThatUsesBSTR(tempBstr.GetBSTR());

Both classes (CComBSTR and bstr_t) are just wrappers that will call SysAllocString and SysFreeString internally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.