Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 515895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:40:31+00:00 2026-05-13T07:40:31+00:00

I’ve written a simple MIDI console application in C++. Here’s the whole thing: #include

  • 0

I’ve written a simple MIDI console application in C++. Here’s the whole thing:

#include <windows.h>
#include <iostream>
#include <math.h>
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 << dwParam1 << " ";
   PlaySound("jingle.wav", NULL, SND_ASYNC | SND_FILENAME);
   break;
 }
}
int main() {
 unsigned int numDevs = midiInGetNumDevs();
 cout << numDevs << " MIDI devices connected:" << endl;
 MIDIINCAPS inputCapabilities;
 for (unsigned int i = 0; i < numDevs; i++) {
  midiInGetDevCaps(i, &inputCapabilities, sizeof(inputCapabilities));
  cout << "[" << i << "] " << inputCapabilities.szPname << endl;
 }
 int portID;
 cout << "Enter the port which you want to connect to: ";
 cin >> portID;
 cout << "Trying to connect with the device on port " << portID << "..." << endl;
 LPHMIDIIN device = new HMIDIIN[numDevs];
 int flag = midiInOpen(&device[portID], portID, (DWORD)&midiInputCallback, 0, CALLBACK_FUNCTION);
 if (flag != MMSYSERR_NOERROR) {
  cout << "Error opening MIDI port." << endl;
  return 1;
 } else {
  cout << "You are now connected to port " << portID << "!" << endl;
  midiInStart(device[portID]);
 }
 while (1) {}
}

You can see that there’s a callback function for handling the incoming MIDI messages from the device. Here is the description of this function on MSDN. On that page they say that the meaning of dwParam1 and dwParam2 are specified to the messagetype (wMsg), like MIM_DATA.

If I look up the documentation of MIM_DATA, I can see that it is a doubleword (DWORD?) 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?

I would appreciate it if somebody can correct my code if it can be done better.

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:40:31+00:00Added an answer on May 13, 2026 at 7:40 am

    To access the data you need to use dwParam1 and dwParam2 and call the macros HIWORD and LOWORD to get the high and low word from them. Respectively use HIBYTE and LOBYTE to get the data out of those words. In case of MIM_DATA, unfortunately that’s byte encoded MIDI data, so you’ll have to find the specific meanings for those — these are documented here — MIDI Messages.

    Your code however has a potential problem — as we read in the MSDN pages:

    “Applications should not call any
    multimedia functions from inside the
    callback function, as doing so can
    cause a deadlock. Other system
    functions can safely be called from
    the callback”.

    And you’re calling PlaySound in the Callback…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.