Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Calling unmanaged DLL-methodes (winmm.dll)

Calling unmanaged DLL-methodes (winmm.dll)

Scheduled Pinned Locked Moved C#
tutorialcsharphelpannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J Holzer
    wrote on last edited by
    #1

    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.

    L O 2 Replies Last reply
    0
    • J J Holzer

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 type private void MidiCallbackFunction(sometype someParameter) { //doStuff } and then you simply do midiInOpen(ref hMidiIn, mMPU401IN, 0, new MidiCallBack(MidiCallbackFunction),0,0); hope this helps greets m@u

      1 Reply Last reply
      0
      • J J Holzer

        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.

        O Offline
        O Offline
        originSH
        wrote on last edited by
        #3

        Theres a great site for .Net interop called pinvoke.net[^]. if you check down the lefthand side you'll see a winmm.dll node down at the bottom :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups