首先要看你的数组里是什么类型的,然后才好定义接口函数转换类型。 你发详细点的说明。比如数组里的是 int ,byte 还是结构类型?你在c++中写一个dll接口函数供c#调用就行了,这个函数的功能就是你需要的,函数参数是(传入数组、下标、返回数组)。这样就可以了。注意这个接口函数中传入数组和返回数组都是在C#中要先定义的,通过这个接口函数c++代码访问c#的内存取数据,计算,然后再往c#内存写入返回数据。
例 c++中定义: int __stdcall ccapGetPicture(int index,,unsigned char *pFrameBuf); 实现: extern "C" int ccapGetPicture(int index,unsigned char *pFrameBuf) { //计算 return capGetPicture(index,pFrameBuf); }c#中定义dll接口函数: [DllImport("CEDll", EntryPoint = "ccapGetPicture")] public static extern int capGetPicture(int index,byte[] pFrameBuf,); 调用函数: int index ; byte[] lpFrameBuffer; lpFrameBuffer = new byte[320*240*3]; capGetPicture(index, lpFrameBuffer);
创建Win32 DLL,并在C#里面调用
http://blog.csdn.net/tangl_99/archive/2006/09/06/1182354.aspx
你发详细点的说明。比如数组里的是 int ,byte 还是结构类型?你在c++中写一个dll接口函数供c#调用就行了,这个函数的功能就是你需要的,函数参数是(传入数组、下标、返回数组)。这样就可以了。注意这个接口函数中传入数组和返回数组都是在C#中要先定义的,通过这个接口函数c++代码访问c#的内存取数据,计算,然后再往c#内存写入返回数据。
c++中定义:
int __stdcall ccapGetPicture(int index,,unsigned char *pFrameBuf);
实现:
extern "C" int ccapGetPicture(int index,unsigned char *pFrameBuf)
{
//计算
return capGetPicture(index,pFrameBuf);
}c#中定义dll接口函数:
[DllImport("CEDll", EntryPoint = "ccapGetPicture")]
public static extern int capGetPicture(int index,byte[] pFrameBuf,);
调用函数:
int index ;
byte[] lpFrameBuffer; lpFrameBuffer = new byte[320*240*3];
capGetPicture(index, lpFrameBuffer);
说明:
我传入int index是图片的序号,传回的是图片的内容,在unsigned char *pFrameBuf这里。
在c#中就是byte[] pFrameBuf收到了c++写过来的图片内容.你明白意思就可以了.
我的函数写成这样也是可以的:
void __stdcall ccapGetPicture(int index,,unsigned char *pFrameBuf);