I have an ActiveX DLL which I try to use in my C# application. Most interop methods work. I am having problems with the following method (the unmanaged definition):
HRESULT SendData([in] long lChID, [in] short nIndex,
[in] VARIANT vData, [out, retval] VARIANT_BOOL *bResult);
The VARIANT data type is unusual for me and I do not know what to do with it as COM and marshalling is a new topic for me.
BOOL CControl::SendData(long lChID, short nIndex, const VARIANT& vData)
{
BOOL result;
static BYTE parms[] = VTS_I4 VTS_I2 VTS_VARIANT;
InvokeHelper(0x1f, DISPATCH_METHOD, VT_BOOL,
(void*)&result, parms, lChID, nIndex, &vData);
return result;
}
I used the .NET tool AxImp.exe to get the managed wrapper for the method:
[DispId(31)]
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType = MethodCodeType.Runtime)]
public virtual bool SendData([In] int lChID, [In] short nIndex,
[MarshalAs(UnmanagedType.Struct), In] object vData);
Is the C# method wrapper correctly generated?
What would be the correct way to initialize and populate the vData parameter?
EDIT:
Some more code example to help decipher the 3rd parameter VARIANT.
VARIANT var;
VariantInit(&var);
var.vt = VT_UI1 | VT_BYREF;
var.pbVal = (unsigned char *)pSend;
if (!m_Control.SendData(m_lCurChID, m_combo.GetCurSel() + 1, var))
AfxMessageBox(_T("SendData failed"));
The var.vt and var.pbVal are not known to me. Is there any corresponding code in C#?