Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.0 KiB

  1. /****************************************************************************
  2. MODULE: joyregst.CPP
  3. Tab stops 5 9
  4. Copyright 1995, 1996, 1999, Microsoft Corporation, All Rights Reserved.
  5. PURPOSE: Methods for VJOYD Registry entries
  6. FUNCTIONS:
  7. Author(s): Name:
  8. ---------- ----------------
  9. MEA Manolito E. Adan
  10. Revision History:
  11. -----------------
  12. Version Date Author Comments
  13. ------- ------ ----- -------------------------------------------
  14. 0.1 20-Jun-96 MEA original
  15. 12-Mar-99 waltw Removed dead joyGetOEMProductName &
  16. joyGetOEMForceFeedbackDriverDLLName
  17. 20-Mar-99 waltw Nuked dead GetRing0DriverName
  18. ****************************************************************************/
  19. #include <windows.h>
  20. #include <mmsystem.h>
  21. #include <regstr.h>
  22. #include <stdio.h>
  23. #include <TCHAR.h>
  24. #include "joyregst.hpp"
  25. #include "sw_error.hpp"
  26. #include "Registry.h"
  27. #include "FFDevice.h"
  28. #include "CritSec.h"
  29. #ifdef _DEBUG
  30. extern char g_cMsg[160];
  31. #endif
  32. //#define ACKNACK_1_16_DEFAULT 0x0000949A
  33. #define ACKNACK_1_16_DEFAULT 0x0000955A
  34. #define ACKNACK_1_20_DEFAULT 0x0000955A
  35. MMRESULT joyGetForceFeedbackCOMMInterface(
  36. IN UINT id,
  37. IN OUT ULONG *pCOMMInterface,
  38. IN OUT ULONG *pCOMMPort)
  39. {
  40. HKEY hOEMForceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  41. DWORD dwcb = sizeof(DWORD);
  42. MMRESULT lr = RegQueryValueEx( hOEMForceFeedbackKey,
  43. REGSTR_VAL_COMM_INTERFACE,
  44. 0, NULL,
  45. (LPBYTE) pCOMMInterface,
  46. (LPDWORD) &dwcb);
  47. if (SUCCESS != lr) return (lr);
  48. lr = RegQueryValueEx( hOEMForceFeedbackKey,
  49. REGSTR_VAL_COMM_PORT,
  50. 0, NULL,
  51. (LPBYTE) pCOMMPort,
  52. (LPDWORD) &dwcb);
  53. #ifdef _DEBUG
  54. g_CriticalSection.Enter();
  55. wsprintf(g_cMsg,"joyGetForceFeedbackCOMMInterface:COMMInterface=%lx, COMMPort=%lx\n",
  56. *pCOMMInterface, *pCOMMPort);
  57. OutputDebugString(g_cMsg);
  58. g_CriticalSection.Leave();
  59. #endif
  60. return (lr);
  61. }
  62. MMRESULT joySetForceFeedbackCOMMInterface(
  63. IN UINT id,
  64. IN ULONG ulCOMMInterface,
  65. IN ULONG ulCOMMPort)
  66. {
  67. HKEY hOEMForceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  68. RegistryKey oemFFKey(hOEMForceFeedbackKey);
  69. oemFFKey.ShouldClose(TRUE); // Close Key on destruction
  70. oemFFKey.SetValue(REGSTR_VAL_COMM_INTERFACE, (BYTE*)(&ulCOMMInterface), sizeof(DWORD), REG_DWORD);
  71. MMRESULT lr = oemFFKey.SetValue(REGSTR_VAL_COMM_PORT, (BYTE*)(&ulCOMMPort), sizeof(DWORD), REG_DWORD);
  72. return (lr);
  73. }
  74. HKEY joyOpenOEMForceFeedbackKey(UINT id)
  75. {
  76. JOYCAPS JoyCaps;
  77. TCHAR szKey[256];
  78. TCHAR szValue[256];
  79. UCHAR szOEMKey[256];
  80. HKEY hKey;
  81. DWORD dwcb;
  82. LONG lr;
  83. // Note: JOYSTICKID1-16 is zero-based, Registry entries for VJOYD is 1-based.
  84. id++;
  85. if (id > joyGetNumDevs() ) return 0;
  86. // open .. MediaResources\CurentJoystickSettings
  87. joyGetDevCaps((id-1), &JoyCaps, sizeof(JoyCaps));
  88. //
  89. #ifdef _NOJOY
  90. strcpy(JoyCaps.szRegKey,"msjstick.drv<0004>");
  91. #endif
  92. //
  93. //
  94. sprintf(szKey,
  95. "%s\\%s\\%s",
  96. REGSTR_PATH_JOYCONFIG,
  97. JoyCaps.szRegKey,
  98. REGSTR_KEY_JOYCURR);
  99. lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPTSTR) &szKey, 0, ((KEY_ALL_ACCESS & ~WRITE_DAC) & ~WRITE_OWNER), &hKey);
  100. if (lr != ERROR_SUCCESS) return 0;
  101. // Get OEM Key name
  102. dwcb = sizeof(szOEMKey);
  103. sprintf(szValue, "Joystick%d%s", id, REGSTR_VAL_JOYOEMNAME);
  104. lr = RegQueryValueEx(hKey, szValue, 0, 0, (LPBYTE) &szOEMKey, (LPDWORD) &dwcb);
  105. RegCloseKey(hKey);
  106. if (lr != ERROR_SUCCESS) return 0;
  107. // open OEM\name\OEMForceFeedback from ...MediaProperties
  108. sprintf(szKey, "%s\\%s\\%s", REGSTR_PATH_JOYOEM, szOEMKey,
  109. REGSTR_OEMFORCEFEEDBACK);
  110. lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, ((KEY_ALL_ACCESS & ~WRITE_DAC) & ~WRITE_OWNER), &hKey);
  111. if (lr != ERROR_SUCCESS)
  112. return 0;
  113. else
  114. return hKey;
  115. }
  116. /******************************************************
  117. **
  118. ** GetAckNackMethodFromRegistry(UINT id)
  119. **
  120. ** @mfunct GetAckNackMethodFromRegistry.
  121. **
  122. ******************************************************/
  123. DWORD GetAckNackMethodFromRegistry(UINT id)
  124. {
  125. HKEY forceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  126. if (forceFeedbackKey == 0) {
  127. return JOYERR_NOCANDO;
  128. }
  129. RegistryKey ffRegKey(forceFeedbackKey);
  130. ffRegKey.ShouldClose(TRUE);
  131. DWORD ackNackInfo = 0;
  132. TCHAR firmwareString[32] = "";
  133. ::wsprintf(firmwareString, TEXT("%d.%d-AckNack"), g_ForceFeedbackDevice.GetFirmwareVersionMajor(), g_ForceFeedbackDevice.GetFirmwareVersionMinor());
  134. DWORD querySize = sizeof(DWORD);
  135. HRESULT queryResult = ffRegKey.QueryValue(firmwareString, (BYTE*)&ackNackInfo, querySize);
  136. if ((queryResult != ERROR_SUCCESS)) {
  137. if (g_ForceFeedbackDevice.GetFirmwareVersionMajor() == 1) {
  138. if (g_ForceFeedbackDevice.GetFirmwareVersionMinor() < 20) {
  139. ackNackInfo = ACKNACK_1_16_DEFAULT;
  140. } else { // 1.20 and greater
  141. ackNackInfo = ACKNACK_1_20_DEFAULT;
  142. }
  143. } else { // Firmware greater than 1.0
  144. ackNackInfo = ACKNACK_1_20_DEFAULT; // Use the latest I know of
  145. }
  146. ffRegKey.SetValue(firmwareString, (BYTE*)&ackNackInfo, sizeof(DWORD), REG_DWORD);
  147. }
  148. return ackNackInfo;
  149. }