我创建了一个 ATL 项目,我得到了一个类似的函数
idl 文件:
[id(1)] HRESULT COM_TEST( [in] int parm_count, [in, out] SAFEARRAY(PARM) *parm, [out, retval] short *return_code )
cpp文件:
STDMETHODIMP CTEST::COM_TEST( int parm_count, SAFEARRAY **parm, short *return_code
{
*return_code = 0;
for( long i = 0 ; i < parmc ; i++ )
{
PARM value;
value.data = _bstr_t("This is a ACK" ); //data is BSTR type
SafeArrayPutElement( *parm, &i, &value );
}
return S_OK;
}
然后我从VB调用它。网
vb 文件:
Dim RetCode As Short
Dim TestArray As ATL_TESTLib.ITEST
Dim parm() As ATL_TESTLib.PARM
TestArray = New ATL_TESTLib.TEST
ReDim parm(1)
parm(0).data = "This is request A"
parm(1).data = "This is request B"
RetCode = TestArray.COM_TEST( 2, parm )
但是,我得到了 AccessViolationException。
我的问题是如何输入一个数组并输出它?