views:

247

answers:

2

Below is the header file.can anyone please give a idea to call the callback function below.

//Function Prototype

int PASCAL EXPORT RegisterCallbackFunctions (TCallbacks CallbackFuncs);

//Data Structure

struct TCallbacks
{
LPONUSSDREQUEST m_pOnRequest;
LPONUSSDRESPONSE m_pOnResponse;
};

struct TData
{
   DWORD  m_dwCmd;     
   BYTE   m_bVersion; 
   BYTE   m_bCodeScheme;   
   DWORD  m_dwErrorCode; 
   char   m_szMsIsdn[15];
}


//Prototypes



typedef int (*LPONUSSDREQUEST) (HANDLE hLoginInstance, HANDLE hDialog, TData data, DWORD *pdwAppParam);

typedef int (*LPONUSSDRESPONSE) (HANDLE hLoginInstance, HANDLE hDialog, char szString [ ], DWORD dwAppParam);

I have already got the hloginInstance and hDialog functions,But I need help in calling the callback function.

regards, Jeanix

A: 

In .NET you could use delegates:

class Program
{
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate int RequestDelegate(
        IntPtr hLoginInstance, 
        IntPtr hDialog, 
        IntPtr data, 
        int pdwAppParam);

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate int ResponseDelegate(
        IntPtr hLoginInstance, 
        IntPtr hDialog, 
        string szString, 
        int dwAppParam);

    [DllImport("somelib.dll")]
    public static extern void RegisterCallbackFunctions(TCallbacks callbacks);

    public struct TCallbacks
    {
        public RequestDelegate m_pOnRequest;
        public ResponseDelegate m_pOnResponse;
    }

    static void Main(string[] args)
    {
        TCallbacks callbacks;
        callbacks.m_pOnRequest = 
            (hLoginInstance, hDialog, data, pdwAppParam) => 10;
        callbacks.m_pOnResponse = 
            (hLoginInstance, hDialog, szString, dwAppParam) => 20;
        RegisterCallbackFunctions(callbacks);
    }
}
Darin Dimitrov
A: 

The Code Doesn't work me, i think there is a problem init.

Error is in this line :- callbacks.m_pOnRequest = (hLoginInstance, hDialog, data, pdwAppParam) => 10;

thankx, jeanix

Jeanix