我有一个名为WD_SDK.dll
的DLL文件(它带有SDK.h
文件)。
我打开SDK.h
,我看到了:
typedef void (CALLBACK * VideoCaptureCB_Ptr)(PVOID pContext, BYTE * apData[3],
VideoSampleInfo_T * pVSI);
typedef struct _VideoSampleInfo_T
{
ULONG idFormat; //
ULONG lSignalState;
int nLen; // not used for raw video data(e.g. YUV420)
int nWidth;
int nHeight;
int anPitchs[3]; // only used for raw video data(e.g. YUV420)
ULONG dwMicrosecsPerFrame; // 1000*1000/FPS
ULONG field;
int iSerial;
} VideoSampleInfo_T;
WD_RegisterVideoPreviewCB(HANDLE hChannel, PVOID pContext, VideoCaptureCB_Ptr pCB);
我想在C#中调用WD_RegisterVideoPreviewCB
。所以我使用DllImport在C#中声明它。它看起来像这样:
[DllImport("WD_SDK.dll", EntryPoint = "_WD_RegisterVideoPreviewCB@12", ExactSpelling = true)]
static extern int WD_RegisterVideoPreviewCB(IntPtr hChannel, object pContext, VideoCaptureCB_Ptr pCB);
然后我在C#中重新声明C ++结构和CALLBACK,如下所示:
public delegate void VideoCaptureCB_Ptr(IntPtr pContext, byte[] apData, VideoSampleInfo_T pVSI);
[StructLayout(LayoutKind.Sequential)]
public struct VideoSampleInfo_T
{
public uint idFormat;
public uint lSignalState;
public int nLen; // not used for raw video data(e.g. YUV420)
public int nWidth;
public int nHeight;
public int[] anPitchs; // only used for raw video data(e.g. YUV420)
public uint dwMicrosecsPerFrame; // 1000*1000/FPS
public uint field;
public int iSerial;
}
一个代表工具
public static void HandleVideoStatic(IntPtr pContext, byte[] apData, VideoSampleInfo_T pVSI)
{
}
当我运行我的代码时:
WD_RegisterVideoPreviewCB(m_ahChannels[i], m_aMediaHandler[i], HandleVideoStatic);
程序显示错误does not match the unmanaged target signature.
我认为PVOID pContext
遇到了问题,我将其更改为对象pContext
。但是我必须将m_aMediaHandler[i]
(它是一个类的实例而不是指针)传递给它,引发错误" .."无效的agruments"
P / S:C ++中的WD_RegisterVideoPreviewCB
调用
WD_RegisterVideoPreviewCB(m_ahChannels[i], &m_aMediaHandler[i], HandleVideoStatic);