
How to pass var length array of string to event in VB
Check the KB article, Q264985:
BUG: ATL Connection Point Wizard-Generated Code for Event
with [out]VARIANT* or [out]long* Argument Gives C4305
Warning
The bool conversion is an error in wizard-generated code.
Fix the wizard-generated code in Fire_...
VariantClear(&varResult);
pvars[0] = &a;
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
The offending line is "pVars[0] = &a".
If you read the documentation of CComVariant, you will see
that there is not a constructor of CComVariant that
accepts a VARIANT*. The compiler does some strange
gyrations that end trying to invoke the constructor that
takes a bool...
You must instead declare a VARIANT, not a CComVariant, and
set it with the correct values for invoking the function.
// CComVariant* pVars = new...
VARIANT Var;
...
// pVars[0] = ...
Var.vt = VT_VARIANT | VT_BYREF;
Var.pvarVal = &a;
...
// DISPPARAMS disp = { pvars, ...
DISPPARAMS disp = { &Var, NULL, 1, 0 };
Quote:
>-----Original Message-----
>I want to fire event in visual basic and pass varlen
array of strings to it.
Quote:
>I added event to interface like this :
> [id(3)] HRESULT SendStrings([in]VARIANT a);
>Generated proxy and Fire_SendStrings looks like
> HRESULT Fire_SendStrings(VARIANT a)
>when I compile i got some errors that 'a' is converted
from struct variant *
Quote:
>into bool
>if i leave all like as it is , I get bool value into
visual basic event, but
Quote:
>if i fix this compile error by removing unreferencing
of 'a' visual basic
>crashes on trying to access any member ...
>I have searched msdn and there are few articles about how
to get and return
>array of strings ,,, but not how to pass it to event.
>--
>Best regards,
>Andrey Koubychev
>.