You could use the multimedia API functions:

Code:
#include <acknex.h>
#include <windows.h>

#define MIDIIN_DEVID 0

void* WINAPI midiInOpen(void **, UINT, DWORD, DWORD, DWORD);
int   WINAPI midiInClose(void*);
int   WINAPI midiInStart(void*);

//-----------------------------------------------------------------------------------------------
void CALLBACK MidiInProc(void* hmi, UINT wMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
	if (wMsg == MIM_DATA)
	{
		// Put your code inside here:
		//
		// dwParam1 is the midi message, where
		//	(dwParam1 & 0xF) is midi channel,
		//	(dwParam1 & 0xF0) is status byte (note on = 0x90, note off = 0x80, ...),
		//	((dwParam1 >> 8) & 0x7F) is data1, eg key,
		//	((dwParam1 >> 16) & 0x7F) is data2, eg velocity 
		//
		// dwParam2 is timestamp
				
	}
}

//-----------------------------------------------------------------------------------------------
void *hmi = NULL; // MidiIn handle

//-----------------------------------------------------------------------------------------------
function main()
{
	if (0 == midiInOpen(&hmi, MIDIIN_DEVID, (DWORD)MidiInProc, 0, CALLBACK_FUNCTION))
	{
		printf("MidiIn successfully opened! Press 'x' to close device");
		midiInStart(hmi); // Ready to receive midi messages
	
		while (! key_x)
		{
			wait(10);
		}
	}
	else
		printf("Failed to open MidiIn!");
	
	if (hmi)
		midiInClose(hmi);
	
	printf("Exit");
}