我在C ++ COM dll中有一个函数
Write( Const VARIANT *pData);
其中VARIANT是结构类型
struct VARIANT
{
unsigned short vt;
unsigned short wReservered;
.....
};
我必须从我的C#代码中调用这个写函数,并将一个多维数组传递给该函数。我按照以下方式进行编组。
c ++代码
:
LBE.h
class CLBE
{
public:
__declspec(dllexport) HRESULT __stdcall Write (/*[in]*/ const VARIANT* pData);
}
其中VARIANT是结构类型
struct VARIANT
{
unsigned short vt;
unsigned short wReservered;
.....
};
LBE.cpp
extern "C"
{
__declspec(dllexport) HRESULT __stdcall Write (const VARIANT* pData)
{
//impl
}
}
c#code
namespace abc
public class dataarea
{
[DLLImport("sample.dll",CallingConvention = CallingConvention.StdCall, EntryPoint = "Write")]
public static extern int Write ([MarshalAs(UnmanagedType.Struct)] ref object pData);
.
.
.
public saveobject()
{
object[,] pVariant;
// populating pVariant
object tempVar = pVarriant;
Write(ref tempVar);
}
}
但是当我从c#调用write函数时,它会抛出一个错误,说“无法找到入口点”写“。有人能解决这个问题吗?