C++ struct to C# With Delegate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gezan
    New Member
    • Aug 2008
    • 3

    C++ struct to C# With Delegate

    Hi all,

    I have a question. The struct below is used to handle the callback of a Unmannaged c++ dll.

    Code:
    struct CALLBACK
    {
    	typedef BOOL (*CALL_AP)	(LPVOID pThis, GT_HANDLE hFrom, GT_ERROR Error, GT_CALLBACK_TYPE dwType, LPVOID pData); 
    	BOOL IsVaild()	{
    		return (m_pCall != NULL);
    	}
    	LPVOID				m_pThis;
    	CALL_AP				m_pCall;
    };
    I tried to translate this struct but probabaly the problem will lie here in the tranalsation of the struct.
    Code:
        [StructLayout(LayoutKind.Sequential)]
        struct CALLBACK
        {
            public delegate bool CALL_AP(IntPtr pThis, UInt32 hFrom, GT_STATUS Status, GT_CALLBACK_TYPE dwType, IntPtr pData);
            public bool IsVaild()
            {
                return m_pCall != null;
            }
            public IntPtr m_pThis;
            public CALL_AP m_pCall;
        }
    but if i use this code the callback function will run 1 time and crash with a unhandled win32 exception
Working...