Unmanaged C++ dll callback RRS feed

  • Question

  • Hi,
    I have a c++ function in a dll

    BOOL __stdcall PlayM4_SetDecCallBack(
        LONG nPort,
        void (CALLBACK* DecCBFun)(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2)

    I want to know if the c# wrapper I wrote would work.

    delegate void DecCBFun(long nPort, ref char pBuf, long nSize, ref FRAME_INFO pFrameInfo, long nReserved1, long nReserved2);

    public static extern Boolean PlayM4_SetDecCallBack(LONG nPort, DecCBFun dcbf);

    does this look right?
    Wednesday, July 19, 2006 3:50 PM


  • Couple of errors. 

    1) long in C++ on Windows generally compiles down into 4 byte number so you should use Int32.  This applies to the 1rst, 3rd, 5th and 6th parameters. 

    2) The second parameter is tricky.  If you intedent for the method to modify the pBuf parameter then use a StringBuilder.  If not use an IntPtr.

    3) Is FRAME_INFO  a struct or class in your C# code?  If it's a class the ref is unnecessary.


    Wednesday, July 19, 2006 10:44 PM