Problem:
I'm using C++ OLE Automation to send data to a MS Excel Spreadsheet.
I'm trying to call Invoke on an IDispatch and I keep getting an unknown
exception.
The objects come from the excel8.olb type library.
Does anybody here know of links, newsgroups, or places to ask
such questions?
Details:
The interface I'm trying to call in Excel is on the IValidation, Add method.
The .olb defines it as such:
[id(0x0000000b5), ....]
void Add(
[in] XlDVType Type,
[in, optional] VARIANT AlertStyle,
[in, optional] VARIANT Operator,
[in, optional] VARIANT Formula1,
[in, optional] VARIANT Formula2);
For my example, only the Type, AlertStyle, and Formula1 are necessary. The
others
are not used.
My c++ code is as follows:
const wchar_t *stupidstr = L"this,is,a,retarded,interface";
hr = pValidation->GetIDsOfNames( IID_NULL, &szAdd, 1, LOCALE_USER_DEFAULT,
&dispID );
if ( SUCCEEDED(hr) )
{
VARIANTARG vargs[5];
DISPPARAMS dp = { 0, 0, 0, 0 };
VariantInit( &vargs[4] );
const int xlValidateList = 3; // from the OLE type lib excel8.olb
vargs[4].vt = VT_I4;
vargs[4].lVal = xlValidateList;
VariantInit( &vargs[3] );
const int xlValidAlertStop = 1;
vargs[3].vt = VT_I4;
vargs[3].lVal = xlValidAlertStop;
VariantInit( &vargs[2] );
vargs[2].vt = VT_ERROR;
vargs[2].scode = DISP_E_PARAMNOTFOUND;
VariantInit( &vargs[1] );
vargs[1].vt = VT_BSTR;
vargs[1].bstrVal = ::SysAllocString( stupidstr );
VariantInit( &vargs[0] );
vargs[0].vt = VT_ERROR;
vargs[0].scode = DISP_E_PARAMNOTFOUND;
dp.rgvarg = vargs;
dp.cArgs = 5;
dp.cNamedArgs = 0;
VARIANT vret;
VariantInit( &vret );
EXCEPINFO excepInfo;
unsigned int index;
hr = pValidation->Invoke( dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
&dp, &vret, &excepInfo, &index );
....
The Invoke is giving me an exception, and the exception is "Exception occured"
:-{
The dispID is correct(it's the Add 0x00b5(181)).
I've tried many combinations to no success. (I tried reversing the parameters
like above.
I've tried ignoring the last(first!? :-/) argument since it's not needed in
this example.)
Thanks,
-DaveS
ps. Don't tell me to import.
pps. Don't tell me to use the OLEDispatchDriver(though it works in this case.)
|