title: C++: Get data from MIDI message (DWORD)
body: <p>I've written a simple MIDI console application in C++. Here's the whole thing:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  using namespace std;
  void CALLBACK midiInputCallback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
   switch (wMsg) {
    case MIM_MOREDATA:
    case MIM_DATA:
     cout &lt;&lt; dwParam1 &lt;&lt; " ";
     PlaySound("jingle.wav", NULL, SND_ASYNC | SND_FILENAME);
     break;
   }
  }
  int main() {
   unsigned int numDevs = midiInGetNumDevs();
   cout &lt;&lt; numDevs &lt;&lt; " MIDI devices connected:" &lt;&lt; endl;
   MIDIINCAPS inputCapabilities;
   for (unsigned int i = 0; i &lt; numDevs; i++) {
    midiInGetDevCaps(i, &amp;inputCapabilities, sizeof(inputCapabilities));
    cout &lt;&lt; "[" &lt;&lt; i &lt;&lt; "] " &lt;&lt; inputCapabilities.szPname &lt;&lt; endl;
   }
   int portID;
   cout &lt;&lt; "Enter the port which you want to connect to: ";
   cin &gt;&gt; portID;
   cout &lt;&lt; "Trying to connect with the device on port " &lt;&lt; portID &lt;&lt; "..." &lt;&lt; endl;
   LPHMIDIIN device = new HMIDIIN[numDevs];
   int flag = midiInOpen(&amp;device[portID], portID, (DWORD)&amp;midiInputCallback, 0, CALLBACK_FUNCTION);
   if (flag != MMSYSERR_NOERROR) {
    cout &lt;&lt; "Error opening MIDI port." &lt;&lt; endl;
    return 1;
   } else {
    cout &lt;&lt; "You are now connected to port " &lt;&lt; portID &lt;&lt; "!" &lt;&lt; endl;
    midiInStart(device[portID]);
   }
   while (1) {}
  }
  </code></pre>
  
  <p>You can see that there's a callback function for handling the incoming MIDI messages from the device. <a href="http://msdn.microsoft.com/en-us/library/dd798460(VS.85).aspx" rel="nofollow noreferrer">Here is the description of this function on MSDN</a>. On that page they say that the meaning of <code>dwParam1</code> and <code>dwParam2</code> are specified to the messagetype (<code>wMsg</code>), like <code>MIM_DATA</code>.</p>
  
  <p>If I look up the documentation of <a href="http://msdn.microsoft.com/en-us/library/dd757284(VS.85).aspx" rel="nofollow noreferrer"><code>MIM_DATA</code></a>, I can see that it is a doubleword (<code>DWORD</code>?) and that it has a 'high word' and a 'low word'. How can I now get data like the name of the control on the MIDI device that sended the data and what value it sends?</p>
  
  <p>I would appreciate it if somebody can correct my code if it can be done better.</p>
  
  <p>Thanks :)</p>