APIENTRY DWORD auxMessage(UINT dwId, UINT uMessage, DWORD dwUser, DWORD dwParam1, DWORD dwParam2) { MMRESULT Result; AUX_DD_VOLUME Volume; DPRINT("auxMessage\n"); // the following cases are documented by DDK switch (uMessage) { case AUXDM_GETDEVCAPS: DPRINT("AUXDM_GETDEVCAPS"); return GetDeviceCapabilities(dwId, AuxDevice, (LPBYTE)dwParam1, (DWORD)dwParam2); case AUXDM_GETNUMDEVS: DPRINT("AUXDM_GETNUMDEVS"); return GetDeviceCount(AuxDevice); case AUXDM_GETVOLUME: DPRINT("AUXDM_GETVOLUME"); Result = AuxGetAudio(dwId, (PBYTE) &Volume, sizeof(Volume)); if (Result == MMSYSERR_NOERROR) { *(LPDWORD)dwParam1 = (DWORD)MAKELONG(HIWORD(Volume.Left), HIWORD(Volume.Right)); } return Result; case AUXDM_SETVOLUME: DPRINT("AUXDM_SETVOLUME"); Volume.Right = HIWORD(dwParam1) << 16; Volume.Left = LOWORD(dwParam1) << 16; return AuxSetAudio(dwId, (PBYTE)&Volume, sizeof(Volume)); } return MMSYSERR_NOERROR; }
APIENTRY DWORD midMessage(DWORD dwId, DWORD dwMessage, DWORD dwUser, DWORD dwParam1, DWORD dwParam2) { DPRINT("midMessage\n"); return MMSYSERR_NOERROR; switch (dwMessage) { case MIDM_GETNUMDEVS: DPRINT("MIDM_GETNUMDEVS"); return GetDeviceCount(MidiInDevice); case MIDM_GETDEVCAPS: DPRINT("MIDM_GETDEVCAPS"); return GetDeviceCapabilities(dwId, MidiInDevice, (LPBYTE)dwParam1, (DWORD)dwParam2); case MIDM_OPEN: DPRINT("MIDM_OPEN"); return MMSYSERR_NOERROR; case MIDM_CLOSE: DPRINT("MIDM_CLOSE"); return MMSYSERR_NOERROR; case MIDM_ADDBUFFER: DPRINT("MIDM_ADDBUFFER"); return MMSYSERR_NOERROR; case MIDM_STOP: DPRINT("MIDM_PAUSE"); return MMSYSERR_NOERROR; case MIDM_START: DPRINT("MIDM_RESTART"); return MMSYSERR_NOERROR; case MIDM_RESET: DPRINT("MIDM_RESET"); return MMSYSERR_NOERROR; default: return MMSYSERR_NOTSUPPORTED; } // the function should never get to this point //FIXME: Would it be wise to assert here? return MMSYSERR_NOTSUPPORTED; }
int thirdspacevest_open_win32(thirdspacevest_device* dev, unsigned int device_index, int get_count) { //Use a series of API calls to find a HID with a specified Vendor IF and Product ID. HIDD_ATTRIBUTES Attributes; SP_DEVICE_INTERFACE_DATA devInfoData; BOOL LastDevice = FALSE; int MemberIndex = 0; LONG Result; int device_count = 0; Length = 0; detailData = NULL; dev->_dev = NULL; /* API function: HidD_GetHidGuid Get the GUID for all system HIDs. Returns: the GUID in HidGuid. */ HidD_GetHidGuid(&HidGuid); /* API function: SetupDiGetClassDevs Returns: a handle to a device information set for all installed devices. Requires: the GUID returned by GetHidGuid. */ hDevInfo=SetupDiGetClassDevs (&HidGuid, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE); devInfoData.cbSize = sizeof(devInfoData); //Step through the available devices looking for the one we want. //Quit on detecting the desired device or checking all available devices without success. MemberIndex = 0; LastDevice = FALSE; do { /* API function: SetupDiEnumDeviceInterfaces On return, MyDeviceInterfaceData contains the handle to a SP_DEVICE_INTERFACE_DATA structure for a detected Requires: The DeviceInfoSet returned in SetupDiGetClassDevs. The HidGuid returned in GetHidGuid. An index to specify a */ Result=SetupDiEnumDeviceInterfaces (hDevInfo, 0, &HidGuid, MemberIndex, &devInfoData); if (Result != 0) { //A device has been detected, so get more information about it. /* API function: SetupDiGetDeviceInterfaceDetail Returns: an SP_DEVICE_INTERFACE_DETAIL_DATA structure containing information about a To retrieve the information, call this function twice. The first time returns the size of the structure in Length. The second time returns a pointer to the data in DeviceInfoSet. Requires: A DeviceInfoSet returned by SetupDiGetClassDevs The SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces. The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure. This application doesn't retrieve or use the structure. If retrieving the structure, set MyDeviceInfoData.cbSize = length of MyDeviceInfoData. and pass the structure's address. */ //Get the Length value. //The call will return with a "buffer too small" error which can be ignored. Result = SetupDiGetDeviceInterfaceDetail (hDevInfo, &devInfoData, NULL, 0, &Length, NULL); //Allocate memory for the hDevInfo structure, using the returned Length. detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length); //Set cbSize in the detailData structure. detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); //Call the function again, this time passing it the returned buffer size. Result = SetupDiGetDeviceInterfaceDetail (hDevInfo, &devInfoData, detailData, Length, &Required, NULL); // Open a handle to the // To enable retrieving information about a system mouse or keyboard, // don't request Read or Write access for this handle. /* API function: CreateFile Returns: a handle that enables reading and writing to the Requires: The DevicePath in the detailData structure returned by SetupDiGetDeviceInterfaceDetail. */ dev->_dev =CreateFile (detailData->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, 0, NULL); /* API function: HidD_GetAttributes Requests information from the Requires: the handle returned by CreateFile. Returns: a HIDD_ATTRIBUTES structure containing the Vendor ID, Product ID, and Product Version Number. Use this information to decide if the detected device is the one we're looking for. */ //Set the Size to the number of bytes in the structure. Attributes.Size = sizeof(Attributes); Result = HidD_GetAttributes (dev->_dev, &Attributes); //Is it the desired device? MyDeviceDetected = FALSE; if ((Attributes.VendorID == THIRDSPACEVEST_VID && Attributes.ProductID == THIRDSPACEVEST_PID)) { if(get_count) { ++device_count; CloseHandle(dev->_dev); } else { MyDeviceDetected = TRUE; MyDevicePathName = detailData->DevicePath; GetDeviceCapabilities(dev->_dev); break; } } else { CloseHandle(dev->_dev); } free(detailData); } //if (Result != 0) else { LastDevice=TRUE; } //If we haven't found the device yet, and haven't tried every available device, //try the next one. MemberIndex = MemberIndex + 1; } while (!LastDevice); SetupDiDestroyDeviceInfoList(hDevInfo); if(get_count) return device_count; if(MyDeviceDetected) return 0; return -1; }
MMRESULT FAR PASCAL modMessage( UINT device_id, UINT message, DWORD_PTR private_data, DWORD_PTR parameter1, DWORD_PTR parameter2) { switch ( message ) { case MODM_GETNUMDEVS : { /* Only one internal PC speaker device (and even that's too much) */ DPRINT("MODM_GETNUMDEVS\n"); return 1; } case MODM_GETDEVCAPS : { DPRINT("MODM_GETDEVCAPS\n"); return GetDeviceCapabilities((MIDIOUTCAPS*) parameter1); } case MODM_OPEN : { DPRINT("MODM_OPEN\n"); return OpenDevice((DeviceInfo**) private_data, (MIDIOPENDESC*) parameter1, parameter2); } case MODM_CLOSE : { DPRINT("MODM_CLOSE\n"); return CloseDevice((DeviceInfo*) private_data); } case MODM_DATA : { return ProcessShortMidiMessage((DeviceInfo*) private_data, parameter1); } case MODM_PREPARE : { /* We don't bother with this */ MIDIHDR* hdr = (MIDIHDR*) parameter1; hdr->dwFlags |= MHDR_PREPARED; return MMSYSERR_NOERROR; } case MODM_UNPREPARE : { MIDIHDR* hdr = (MIDIHDR*) parameter1; hdr->dwFlags &= ~MHDR_PREPARED; return MMSYSERR_NOERROR; } case MODM_LONGDATA : { DPRINT("LONGDATA\n"); return ProcessLongMidiMessage((DeviceInfo*) private_data, (MIDIHDR*) parameter1); } case MODM_RESET : { /* TODO */ break; } } DPRINT("Not supported %d\n", message); return MMSYSERR_NOTSUPPORTED; }
APIENTRY DWORD modMessage(DWORD ID, DWORD Message, DWORD User, DWORD Param1, DWORD Param2) { DPRINT("modMessage\n"); switch(Message) { case MODM_GETNUMDEVS: DPRINT("MODM_GETNUMDEVS == %d\n", (int)GetDeviceCount(MidiOutDevice)); return GetDeviceCount(MidiOutDevice); case MODM_GETDEVCAPS: DPRINT("MODM_GETDEVCAPS"); return GetDeviceCapabilities(ID, MidiOutDevice, (LPBYTE)Param1, (DWORD)Param2); case MODM_OPEN : return OpenMidiDevice(MidiOutDevice, ID, User, Param1, Param2); case MODM_CLOSE: DPRINT("MODM_CLOSE"); return MMSYSERR_NOTSUPPORTED; case MODM_DATA: DPRINT("MODM_DATA"); int i; BYTE b[4]; for (i = 0; i < 4; i ++) { b[i] = (BYTE)(Param1 % 256); Param1 /= 256; } return WriteMidi(b, GetMidiLength((PMIDIALLOC)User, b[0]), (PMIDIALLOC)User); case MODM_LONGDATA: DPRINT("MODM_LONGDATA"); return MMSYSERR_NOTSUPPORTED; case MODM_RESET: DPRINT("MODM_RESET"); return MMSYSERR_NOTSUPPORTED; case MODM_SETVOLUME: DPRINT("MODM_SETVOLUME"); return MMSYSERR_NOTSUPPORTED; case MODM_GETVOLUME: DPRINT("MODM_GETVOLUME"); return MMSYSERR_NOTSUPPORTED; case MODM_CACHEPATCHES: DPRINT("MODM_CACHEPATCHES"); return MMSYSERR_NOTSUPPORTED; case MODM_CACHEDRUMPATCHES: DPRINT("MODM_CACHEDRUMPATCHES"); return MMSYSERR_NOTSUPPORTED; }; return MMSYSERR_NOTSUPPORTED; }