Need help with a MFC client with SAFEARRAY argument
MFC client access a VB COM Server with SAFEARRAY argument
Hi all,
I am writing a personal program and ran into a major ostacle. I tried it for
over and can not figure it out. I would appreciate any comment and help from
you guys.
I am writing a MFC program. This program will interface a vendor program
which ONLY provide VB support. Actually the vendor program was written in VB
obviousely.
I have no problem if the method does not have a SAFEARRAY argument. However,
many methods have SAFEARRAY arguments. Even worse, this program only allow
you to do late-binding, no TLibrary is provided.
For example, one method called
Sub GetAllChartListSorts(SortNames() As String)
Sound simple, but if I write code like this -
OLECHAR FAR* szMember2 = L"GetAllChartListSorts";
hr=m_server.m_lpDispatch->GetIDsOfNames( IID_NULL, &szMember2, 1,
LOCALE_USER_DEFAULT, &dispid);
VARIANT return_val;
EXCEPINFO ExceptionInfo;
unsigned int uArgErr;
DISPPARAMS dp;
VariantInit(&return_val);
//create DISPPARAMS struct
dp.cArgs = 1;
dp.rgvarg = new VARIANTARG;
dp.rgvarg->vt=VT_ARRAY|VT_BSTR;
dp.rgvarg->parray = NULL;
dp.cNamedArgs = 0;
dp.rgdispidNamedArgs = NULL;
//invoke the call
hr = m_server.m_lpDispatch->Invoke( dispid, IID_NULL,
LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD, &dp, &return_val, &ExceptionInfo,
&uArgErr);
The method call return S_OK, but I can find nothing in the DISPARAMS. The
array is not filled up.
The Visual Basic client works just fine.
dim a() as String
Server.GetAllChartListSorts a()
I doubted that the SAFEARRAY might not be properly filled. I verified that
by implementing a COM Server and let a VB client sends a dynamic array
argument. It proves that my way of filling was correct.
However, the code does work. Anything wrong here?