Hi,
I'm currently trying to port an application to c#. I need to receive some callbacks from unmanaged C DLL. I understand I woudl have to use delegates in c#. The API for the DLL includes a structure of function pointers:
typedef struct tagCALLBACKS
{
void ( *SetupInd ) ( int, char *, char* );
void ( *AlertingInd ) ( int );
void ( *ProceedingInd ) ( int );
void ( *ConnectInd ) ( int );
void ( *DisconnectInd ) ( int );
void ( *TransmitDtmfInd ) ( int, char * );
void ( *RequestIdInd ) ( int, int );
}CALLBACKS;
So, in c# I have a class called CALLBACKS that contains my delegates:
public delegate void SetupCallbackDelegate( int id, byte [] toAddress, byte [] fromAddress );
public delegate void AlertingCallbackDelegate( int id );
public delegate void ProceedingCallbackDelegate( int id );
public delegate void ConnectCallbackDelegate( int id );
public delegate void DisconnectCallbackDelegate( int id );
public delegate void TransmitDtmfCallbackDelegate( int id, byte [] toneString );
public delegate void RequestIdCallbackDelegate( int id, int uniqueId );
[StructLayout(LayoutKind.Sequential)]
public class CALLBACKS
{
[MarshalAs(UnmanagedType.FunctionPtr)]
public SetupCallbackDelegate SetupInd;
[MarshalAs(UnmanagedType.FunctionPtr)]
public AlertingCallbackDelegate AlertingInd;
[MarshalAs(UnmanagedType.FunctionPtr)]
public ProceedingCallbackDelegate ProceedingInd;
[MarshalAs(UnmanagedType.FunctionPtr)]
public ConnectCallbackDelegate ConnectInd;
[MarshalAs(UnmanagedType.FunctionPtr)]
public DisconnectCallbackDelegate DisconnectInd;
[MarshalAs(UnmanagedType.FunctionPtr)]
public TransmitDtmfCallbackDelegate TransmitDtmfInd;
[MarshalAs(UnmanagedType.FunctionPtr)]
public RequestIdCallbackDelegate RequestIdInd;
}
There is then a function that adds the callback structure:
[DllImport("ScriptDLL.dll",CallingConvention=CallingConvention.Cdecl)]
public static extern int AddCallbackListener( CALLBACKS cb );
I've probably misunderstand the concept here, but I'm relatively new to C#, but I mainly use C/C++. Any help/pointers would be gratefully received.
Regards,
Paul.
Callbacks in c# from unmanaged C DLL
Started by
Guest_paul_chapman_*
, Jan 18 2007 08:26 AM
No replies to this topic
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Guest_paul_chapman_*
Back to top









