I have an DLL file named WD_SDK.dll ( it go with an SDK.h file ). I open the SDK.h and I see
typedef void (CALLBACK * VideoCaptureCB_Ptr)(PVOID pContext, BYTE * apData[3],
VideoSampleInfo_T * pVSI);
typedef struct _VideoSampleInfo_T
{
ULONG idFormat; ULONG lSignalState;
int nLen; int nWidth;
int nHeight;
int anPitchs[3]; ULONG dwMicrosecsPerFrame; ULONG field;
int iSerial;
} VideoSampleInfo_T;
WD_RegisterVideoPreviewCB(HANDLE hChannel, PVOID pContext, VideoCaptureCB_Ptr pCB);
I want to call the WD_RegisterVideoPreviewCB in C#. So I use the DllImport to declare it in C#. It look like this:
[DllImport("WD_SDK.dll", EntryPoint = "_WD_RegisterVideoPreviewCB@12", ExactSpelling = true)]
static extern int WD_RegisterVideoPreviewCB(IntPtr hChannel, object pContext, VideoCaptureCB_Ptr pCB);
Then i re-declare the C++ struct and CALLBACK in C# like this:
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;
public int nWidth;
public int nHeight;
public int[] anPitchs;
public uint dwMicrosecsPerFrame;
public uint field;
public int iSerial;
}
And one delegate implement
When i run my code
WD_RegisterVideoPreviewCB(m_ahChannels[i], m_aMediaHandler[i], HandleVideoStatic);
THe program show me an error "does not match the unmanaged target signature. "
I thinks encountered problem with the PVOID pContext, I changed it to object pContext. But i have to pass the m_aMediaHandler[i] ( It's an instance of a class not a pointer ) to it, the error raised " .."invalid agruments"
Please help me to correct this code. Thanks in advance.