Strange DLL Calls in C# - Help
-
Hello All, I'm attempting to create a C# Wrapper around a DLL from Diamond Systems. The problem I'm having is that the DLL is very dependant on Pointers. I've suffered through must of it already, with a lot of help from these boards. However I've run into something I can't find an answer for: I need to pass a Struct containing a Pointer to a Function. Here is the C++ Code: typedef struct { DSCUserInterruptFunction func; BYTE int_mode; } DSCUSERINTFUNCTION; typedef void (*DSCUserInterruptFunction) (void* parameter); The DLL call is: BYTE dscSetUserInterruptFunction(DSCB board, DSCUSERINTFUNCTION* dscuserintfunction); Diamond Systems manual: http://docs.diamondsystems.com/dscud/manual\_DSCUD\_Function\_Reference.html If I can get this to run then the project is complete! Thanks in advance for any help you can offer me. If it is of any interest I just placed my order for next years MSDN subscription through Code Project, thus becomming a supporting member. Thanks again. -Marc
-
Hello All, I'm attempting to create a C# Wrapper around a DLL from Diamond Systems. The problem I'm having is that the DLL is very dependant on Pointers. I've suffered through must of it already, with a lot of help from these boards. However I've run into something I can't find an answer for: I need to pass a Struct containing a Pointer to a Function. Here is the C++ Code: typedef struct { DSCUserInterruptFunction func; BYTE int_mode; } DSCUSERINTFUNCTION; typedef void (*DSCUserInterruptFunction) (void* parameter); The DLL call is: BYTE dscSetUserInterruptFunction(DSCB board, DSCUSERINTFUNCTION* dscuserintfunction); Diamond Systems manual: http://docs.diamondsystems.com/dscud/manual\_DSCUD\_Function\_Reference.html If I can get this to run then the project is complete! Thanks in advance for any help you can offer me. If it is of any interest I just placed my order for next years MSDN subscription through Code Project, thus becomming a supporting member. Thanks again. -Marc
You need to read up on delegates in C#, I would recommend you start here: Delegates Tutorial[^] from the C# Programmer's Reference. - Nick Parker
My Blog | My Articles -
Hello All, I'm attempting to create a C# Wrapper around a DLL from Diamond Systems. The problem I'm having is that the DLL is very dependant on Pointers. I've suffered through must of it already, with a lot of help from these boards. However I've run into something I can't find an answer for: I need to pass a Struct containing a Pointer to a Function. Here is the C++ Code: typedef struct { DSCUserInterruptFunction func; BYTE int_mode; } DSCUSERINTFUNCTION; typedef void (*DSCUserInterruptFunction) (void* parameter); The DLL call is: BYTE dscSetUserInterruptFunction(DSCB board, DSCUSERINTFUNCTION* dscuserintfunction); Diamond Systems manual: http://docs.diamondsystems.com/dscud/manual\_DSCUD\_Function\_Reference.html If I can get this to run then the project is complete! Thanks in advance for any help you can offer me. If it is of any interest I just placed my order for next years MSDN subscription through Code Project, thus becomming a supporting member. Thanks again. -Marc
try this:
delegate void DSCUserInterruptFunction (IntPtr param);
struct DSCUSERINTFUNCTION
{
public DSCUserInterruptFunction func;
public byte mode;
}[DllImport(diamond.dll)]
extern static byte dscSetUserInterruptFunction(DSCB board, ref DSCUSERINTFUNCTION dscuserintfunction);static void DSCUserInterruptFunctionImpl(IntPtr param)
{}
DSCUSERINTFUNCTION foo = new DSCUSERINTFUNCTION();
foo.func = new DSCUserInterruptFunction(DSCUserInterruptFunctionImpl);byte result = dscSetUserInterruptFunction(board, ref foo);
top secret
Download xacc-ide 0.0.3 now!
See some screenshots