R
renjini
I am a starter in C# ...
I will present my problem :
I am wrapping a C dll in C#. The C dll exports a function which takes a
structure MYSTRUCT holding 2 function pointers(callback functions).
struct MYSTRUCT
{
ontest1 t1;
ontest2 t2
};
where ontest1 and ontest2 are two function pointers.
In C# dll, I have declared this structure as
[StructLayout(LayoutKind.Sequential)]
public struct MYSTRUCT
{
[MarshalAs(UnmanagedType.FunctionPtr)]
ontest1 t1;
[MarshalAs(UnmanagedType.FunctionPtr)]
ontest2 t2
}
where ontest1 and ontest2 are two delegates.
//Importing the C dll function "MyFunctions"
[DllImport("mydll.dll")]
IntPtr MyFunctions(IntPtr myStruct);
//The .NET function wrapping the above function :
IntPtr MyFunctions1(ref MYSTRUCT mystruct)
{
//Converts MYSTRUCT to pointer
GCHandle callbackHandle = GCHandle.Alloc
(mystruct ,GCHandleType.Pinned);
IntPtr mystructptr = callbackHandle.AddrOfPinnedObject();
//Calls the imported C dll function
IntPtr handle = MyFunctions(mystructptr);
return handle;
}
The address in the delegates in MYSTRUCT are stored inside the C dll..
and the same functions are invoked whenever an event occurs. That is
the unmanaged code calls the managed code asynchronously.
The call to the C dll is working fine.. but whenever an event occurs
the registered function is not getting involked..
Do I have to add/remove anything more to the code?
Any help will be appreciated...
regards
Renjini
I will present my problem :
I am wrapping a C dll in C#. The C dll exports a function which takes a
structure MYSTRUCT holding 2 function pointers(callback functions).
struct MYSTRUCT
{
ontest1 t1;
ontest2 t2
};
where ontest1 and ontest2 are two function pointers.
In C# dll, I have declared this structure as
[StructLayout(LayoutKind.Sequential)]
public struct MYSTRUCT
{
[MarshalAs(UnmanagedType.FunctionPtr)]
ontest1 t1;
[MarshalAs(UnmanagedType.FunctionPtr)]
ontest2 t2
}
where ontest1 and ontest2 are two delegates.
//Importing the C dll function "MyFunctions"
[DllImport("mydll.dll")]
IntPtr MyFunctions(IntPtr myStruct);
//The .NET function wrapping the above function :
IntPtr MyFunctions1(ref MYSTRUCT mystruct)
{
//Converts MYSTRUCT to pointer
GCHandle callbackHandle = GCHandle.Alloc
(mystruct ,GCHandleType.Pinned);
IntPtr mystructptr = callbackHandle.AddrOfPinnedObject();
//Calls the imported C dll function
IntPtr handle = MyFunctions(mystructptr);
return handle;
}
The address in the delegates in MYSTRUCT are stored inside the C dll..
and the same functions are invoked whenever an event occurs. That is
the unmanaged code calls the managed code asynchronously.
The call to the C dll is working fine.. but whenever an event occurs
the registered function is not getting involked..
Do I have to add/remove anything more to the code?
Any help will be appreciated...
regards
Renjini