日期:2014-05-18  浏览次数:20903 次

C#调用C++ DLL接口参数的问题(参数与指针相关)
C++写的dll中有一个接口函数是这么定义的
[code=C/C++]
//创建一个实例
int   CreateInstance(INST*   instance);
//INST是如下定义的
typedef   struct
{
        void   *   instance;
}   *INST;
[/code]
请问我在C++中要用这个接口,该如何声明

[code=C#]
[DllImport( "w_vad_win32.dll ")]
public   static   extern   int   CreateInstance(???);
[/code]

我是C#新手,请各位大虾指教!

------解决方案--------------------
IntPtr,
或者用unsafe关键字。


------解决方案--------------------
IntPtr

http://msdn.microsoft.com/zh-cn/library/s69bkh17.aspx

http://msdn.microsoft.com/zh-cn/library/system.runtime.interopservices.marshal(v=VS.80).aspx

//申请内存
IntPtr hglobal = Marshal.AllocHGlobal(100);
//
CreateInstance()

//释放内存 
Marshal.FreeHGlobal(hglobal);