c++文件中函数定义如下:

extern "C"
{
 //__stdcall即callback
 __declspec(dllexport) int __stdcall f_Test(unsigned char pInput[], char ifn[100])
 {

     return 1;
 }
}

c#文件中函数调用如下:

 [DllImport("Test.dll")]//Test.dll是c++文件生成的dll
static extern int f_Test(byte[] pInput, String fileName);

byte[] Minput = new byte[100];

 f_Test(Minput, fileName);

如果传递的参数为结构体,则必须在c#端定义数据成员类型相对应的结构体。

struct point{
 unsigned short xpos;               
 unsigned short ypos;               

} ;

C#端定义如下:

public struct point
{
     public ushort xpos;              
     public ushort ypos;              
 };

这是我刚刚开始做,自己摸索处来结果。

posted on 2009-03-11 12:57  风信子杨  阅读(517)  评论(1)    收藏  举报