Source code of Windows XP (NT5)
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.

237 lines
5.5 KiB

  1. /****************************************************************************
  2. *
  3. * drvlib.c
  4. *
  5. * Multimedia kernel driver support library (drvlib)
  6. *
  7. * Copyright (c) 1993-1995 Microsoft Corporation
  8. *
  9. * This module contains
  10. *
  11. * -- the entry point and startup code
  12. * -- debug support code
  13. *
  14. * History
  15. *
  16. ***************************************************************************/
  17. #include <drvlib.h>
  18. #include <stdarg.h>
  19. #include <stdlib.h>
  20. CRITICAL_SECTION mmDrvCritSec; // Serialize access to device lists
  21. #if DBG
  22. char ModuleName[MAX_PATH];
  23. #endif
  24. #if DBG
  25. /*
  26. * read profile item from registry
  27. */
  28. //#include <profile.key>
  29. #define KEYNAMEA "Software\\Microsoft\\Multimedia\\"
  30. #define KEYNAME TEXT("Software\\Microsoft\\Multimedia\\")
  31. #define KEYNAMEW KEYNAME
  32. #define ROOTKEY HKEY_CURRENT_USER
  33. UINT mmGetProfileIntA(LPCSTR appname, LPCSTR valuename, INT uDefault);
  34. // Now map all instances of GetProfileIntA to mmGetProfileIntA
  35. #define GetProfileIntA mmGetProfileIntA
  36. static HKEY GetKeyA(LPCSTR appname, BOOL fCreate)
  37. {
  38. HKEY key = 0;
  39. char achName[MAX_PATH];
  40. lstrcpyA(achName, KEYNAMEA);
  41. lstrcatA(achName, appname);
  42. if ((!fCreate && RegOpenKeyA(ROOTKEY, achName, &key) == ERROR_SUCCESS)
  43. || (fCreate && RegCreateKeyA(ROOTKEY, achName, &key) == ERROR_SUCCESS)) {
  44. }
  45. return(key);
  46. }
  47. /*
  48. * read a UINT from the profile, or return default if
  49. * not found.
  50. */
  51. UINT
  52. mmGetProfileIntA(LPCSTR appname, LPCSTR valuename, INT uDefault)
  53. {
  54. DWORD dwType;
  55. INT value = uDefault;
  56. DWORD dwData;
  57. int cbData;
  58. HKEY key = GetKeyA(appname, FALSE);
  59. if (key) {
  60. cbData = sizeof(dwData);
  61. if (RegQueryValueExA(
  62. key,
  63. (LPSTR)valuename,
  64. NULL,
  65. &dwType,
  66. (PBYTE) &dwData,
  67. &cbData) == ERROR_SUCCESS) {
  68. if (dwType == REG_DWORD || dwType == REG_BINARY) {
  69. value = (INT)dwData;
  70. } else if (dwType == REG_SZ) {
  71. value = atoi((LPSTR) &dwData);
  72. }
  73. }
  74. RegCloseKey(key);
  75. }
  76. return((UINT)value);
  77. }
  78. #endif // DBG
  79. /**************************************************************************
  80. @doc EXTERNAL
  81. @api BOOL | DllInstanceInit | This procedure is called whenever a
  82. process attaches or detaches from the DLL.
  83. @parm PVOID | hModule | Handle of the DLL.
  84. @parm ULONG | Reason | What the reason for the call is.
  85. @parm PCONTEXT | pContext | Some random other information.
  86. @rdesc The return value is TRUE if the initialisation completed ok,
  87. FALSE if not.
  88. **************************************************************************/
  89. BOOL DrvLibInit(HINSTANCE hModule, ULONG Reason, PCONTEXT pContext)
  90. {
  91. UNREFERENCED_PARAMETER(pContext);
  92. if (Reason == DLL_PROCESS_ATTACH) {
  93. #if DBG
  94. /*
  95. ** Cache our dll name for debugging
  96. */
  97. {
  98. char ModuleFileName[MAX_PATH];
  99. if (GetModuleFileNameA((HMODULE)hModule, ModuleFileName, MAX_PATH) ==
  100. 0) {
  101. mmdrvDebugLevel = 0;
  102. } else {
  103. char drive[MAX_PATH];
  104. char dir[MAX_PATH];
  105. char ext[MAX_PATH];
  106. // note: we could use the WIN32 API GetFileTitle
  107. _splitpath(ModuleFileName, drive, dir, ModuleName, ext);
  108. mmdrvDebugLevel = GetProfileIntA("DEBUG", ModuleName, 0);
  109. dprintf2 (("Starting, debug level=%d", mmdrvDebugLevel));
  110. }
  111. }
  112. #endif
  113. hInstance = hModule;
  114. //
  115. // Create our process DLL heap
  116. //
  117. hHeap = GetProcessHeap();
  118. if (hHeap == NULL) {
  119. return FALSE;
  120. }
  121. DisableThreadLibraryCalls(hModule);
  122. InitializeCriticalSection(&mmDrvCritSec);
  123. //
  124. // Load our device list
  125. //
  126. if (sndFindDevices() != MMSYSERR_NOERROR) {
  127. DeleteCriticalSection(&mmDrvCritSec);
  128. return FALSE;
  129. }
  130. } else {
  131. if (Reason == DLL_PROCESS_DETACH) {
  132. dprintf2(("Ending"));
  133. TerminateMidi();
  134. TerminateWave();
  135. DeleteCriticalSection(&mmDrvCritSec);
  136. }
  137. }
  138. return TRUE;
  139. }
  140. #if DBG
  141. int mmdrvDebugLevel = 0;
  142. /***************************************************************************
  143. @doc INTERNAL
  144. @api void | mmdrvDbgOut | This function sends output to the current
  145. debug output device.
  146. @parm LPSTR | lpszFormat | Pointer to a printf style format string.
  147. @parm ??? | ... | Args.
  148. @rdesc There is no return value.
  149. ****************************************************************************/
  150. void mmdrvDbgOut(LPSTR lpszFormat, ...)
  151. {
  152. char buf[256];
  153. va_list va;
  154. OutputDebugStringA(ModuleName);
  155. OutputDebugStringA(": ");
  156. va_start(va, lpszFormat);
  157. vsprintf(buf, lpszFormat, va);
  158. va_end(va);
  159. OutputDebugStringA(buf);
  160. OutputDebugStringA("\n");
  161. }
  162. /***************************************************************************
  163. @doc INTERNAL
  164. @api void | dDbgAssert | This function prints an assertion message.
  165. @parm LPSTR | exp | Pointer to the expression string.
  166. @parm LPSTR | file | Pointer to the file name.
  167. @parm int | line | The line number.
  168. @rdesc There is no return value.
  169. ****************************************************************************/
  170. void dDbgAssert(LPSTR exp, LPSTR file, int line)
  171. {
  172. dprintf1(("Assertion failure:"));
  173. dprintf1((" Exp: %s", exp));
  174. dprintf1((" File: %s, line: %d", file, line));
  175. DebugBreak();
  176. }
  177. #endif // DBG