急!求救,分不够再加。C#中调用C++写的DLL出错,大侠请出手相救。
DLL中函数原型(C++写的):
typedef int (*STREAM_READ_CALLBACK )(ULONG channelNumber,
UCHAR *pStreamBuffer,
DWORD Length,
int FrameType);
#define IMEAPI extern "C"__declspec(dllexport)
IMEAPI int __stdcall RegisterStreamReadCallback(HANDLE hChannelHandle,
STREAM_READ_CALLBACK StreamReadCallback);
我在C#中定义:
unsafe public delegate int STREAM_READ_CALLBACK(ulong channelNumber,
byte* pStreamBuffer,
ulong Length,
int FrameType);
[DllImport("NV6000SDK", CallingConvention=CallingConvention.StdCall)]
public static extern int RegisterStreamReadCallback(IntPtr hChannelHandle,
STREAM_READ_CALLBACK StreamReadCallback);
我在C#里面声明了一个回调函数:
unsafe public static int OnData(ulong channelNumber,
byte* pStreamBuffer,
ulong Length,
int FrameType)
{
.
. //此处太多,已省略
.
return 0;
}
我在C#里面调用下面的函数时出错:
RegisterStreamReadCallback(i, new STREAM_READ_CALLBACK(OnData));
此时提示“MyProc.exe 遇到问题需要关闭。我们对此引起的不便表示抱歉。”
通过反复测试,估计是回调函数中第2个参数
byte* pStreamBuffer
引起的,但我不知道如何解决此问题,望高手指教!!!!!