In C++, I'm trying to call an OLE method which looks like this:
HRESULT GetFirstMono(
[out] BSTR* name,
[out, retval] BSTR* monoID);
I use the following code to call it (adapted from http://www.codeproject.com/KB/office/MSOfficeAuto.aspx ):
int cArgs = 1;
DISPPARAMS dp = { NULL, NULL, 0, 0 };
DISPID dispidNamed = DISPID_PROPERTYPUT;
DISPID dispID;
VARIANT *pArgs = new VARIANT[cArgs+1];
// Extract arguments...
for(int i=0; i<cArgs; i++) {
pArgs[i] = va_arg(marker, VARIANT);
}
// Build DISPPARAMS
dp.cArgs = cArgs;
dp.rgvarg = pArgs;
// Make the call!
hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, nType, &dp,
pvResult, NULL, NULL);
if(cArgs == 1) {
std::cout << "oleCall()" << std::endl;
std::cout << "vt: " << dp.rgvarg[0].vt << std::endl;
}
The program excecutes without crashing, and I receive the monoId output BSTR* in pvResult
(and I get the value that I expect). But instead of finding name, I only get an empty variant in dp:rgvarg[0]
, i.e. on my terminal I see
oleCall()
vt: 0
. The exact same method works fine when I call it from LabView, so I figure the problem is somewhere in my code. How can I recover the name output?