Calling unmanaged DLL-methodes (winmm.dll)
-
Hi! I'd like to attach to winmm.dll from C# (VS2005) and translated a few DLLImports from a very old VB6-Code i found on the internet. Some methods have callbacks and i don't know how to translate them. The methods look like this: public static extern int midiInOpen(ref int lphMidiIn, int uDeviceID, int dwCallback, int dwInstance, int dwFlags); and public void MidiIN_Proc(long hmIN, long wMsg, int dwInstance, int dwParam1, int dwParam2) The method should somehow work like this: midiInOpen(ref hMidiIN, mMPU401IN, 0, CALLBACK_FUNCTION); The problem is, that in the original version dwInstance and dwCallback are pointers to methods. Unfortunately i have no clue how to use these DLL-calls in C#. Can anybody tell me how to do these DLL-calls or provide some example-code= Thanx a lot! J.
-
Hi! I'd like to attach to winmm.dll from C# (VS2005) and translated a few DLLImports from a very old VB6-Code i found on the internet. Some methods have callbacks and i don't know how to translate them. The methods look like this: public static extern int midiInOpen(ref int lphMidiIn, int uDeviceID, int dwCallback, int dwInstance, int dwFlags); and public void MidiIN_Proc(long hmIN, long wMsg, int dwInstance, int dwParam1, int dwParam2) The method should somehow work like this: midiInOpen(ref hMidiIN, mMPU401IN, 0, CALLBACK_FUNCTION); The problem is, that in the original version dwInstance and dwCallback are pointers to methods. Unfortunately i have no clue how to use these DLL-calls in C#. Can anybody tell me how to do these DLL-calls or provide some example-code= Thanx a lot! J.
Hi. i think you will first have to declare a delegate with the paramters of the callback-function
public delegate void MidiCallBack(sometype someParameter);
then declare the API - Call[DllImport("winmm.dll")] public static extern int midiInOpen(ref int lphMidiIn, int uDeviceID, [MarshalAs(UnmanagedType.FunctionPtr)]MidiCallBack dwCallback, int dwInstance, int dwFlags);
then you define the callback function with the same typeprivate void MidiCallbackFunction(sometype someParameter) { //doStuff }
and then you simply domidiInOpen(ref hMidiIn, mMPU401IN, 0, new MidiCallBack(MidiCallbackFunction),0,0);
hope this helps greets m@u -
Hi! I'd like to attach to winmm.dll from C# (VS2005) and translated a few DLLImports from a very old VB6-Code i found on the internet. Some methods have callbacks and i don't know how to translate them. The methods look like this: public static extern int midiInOpen(ref int lphMidiIn, int uDeviceID, int dwCallback, int dwInstance, int dwFlags); and public void MidiIN_Proc(long hmIN, long wMsg, int dwInstance, int dwParam1, int dwParam2) The method should somehow work like this: midiInOpen(ref hMidiIN, mMPU401IN, 0, CALLBACK_FUNCTION); The problem is, that in the original version dwInstance and dwCallback are pointers to methods. Unfortunately i have no clue how to use these DLL-calls in C#. Can anybody tell me how to do these DLL-calls or provide some example-code= Thanx a lot! J.