Click here to Skip to main content
15,443,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; // 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);

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);

    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;


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.
Updated 26-Mar-14 8:10am
Richard MacCutchan 26-Mar-14 13:59pm    
Have you marked this function as exported in the DLL?
Richard MacCutchan 26-Mar-14 14:00pm    

1 solution

I don't know where did you get "_WD_RegisterVideoPreviewCB@12". This name looks realistic, but better check it up.

The simplest way to do so is running some binary dump utility on your exported DLL. It can be DUMPBIN.EXE:[^].

You can run this utility from the Visual Studio Command Prompt found in Visual Studio menu.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900