C# 传递数组参数到
C# 调用
string []dropFiles = {“1”, “2”, “3”};
object fileList = dropFiles;
comWrapper.somemethod( ref fileList);
C++ COM函数定义
STDMETHODIMP CcomWrapper::somemethod( VARIANT* fileList )
{
。。。。。。。
ong len=fileList->parray->rgsabound[0].cElements;
BSTR *pData=new BSTR[len];
for (LONG i=0;i < len; i++)
{
::SafeArrayGetElement(fileList->parray,&i,pData+i);
}
。。。。。。。。
}
COM 返回数组到 C#
COM
[id(16), helpstring("method GetAllButtons")] HRESULT GetAllButtons([in] IUnknown* pDSMenu,[out,retval] VARIANT* ppButtonList);
STDMETHODIMP CCDSProjectUtilitiesProxy::GetAllButtons( IUnknown* pDSMenu, VARIANT* ppButtonList)
{
HRESULT hr = S_OK;
CComSafeArray<VARIANT> m_sa;
IDSMenuPtr spMenu = (IDSMenuPtr)pDSMenu;
if(spMenu)
{
DSSortedButtonVec btnCmdVec(spMenu);
for( int x=0; x < (int) btnCmdVec.size(); x++ )
{
CComPtr<IDSMenuButton> spBtn = btnCmdVec[x];
if( spBtn != NULL )
{
m_sa.Add(CComVariant(spBtn));
}
}
CComVariant var(m_sa);
var.Detach(ppButtonList);
}
return hr;
}
C#
bject buttonsArray = projectUtilitiesProxy.GetAllButtons(dsMenu);
本文介绍了如何在C#中调用COM组件,并传递字符串数组作为参数,以及如何从COM组件接收返回的数组。示例中展示了C#调用COM方法的语法,以及COM组件内部处理数组的方法。同时,展示了COM方法如何返回一个包含IDSMenuButton对象的VARIANT数组到C#。
890

被折叠的 条评论
为什么被折叠?



