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.

116 lines
2.6 KiB

  1. // Copyright (c) 1998 Microsoft Corporation
  2. // dm32dll.cpp
  3. //
  4. // Dll entry points
  5. //
  6. #include <objbase.h>
  7. #include <assert.h>
  8. #include <mmsystem.h>
  9. #include <dsoundp.h>
  10. #include "dmusicc.h"
  11. #include "..\dmusic\dmusicp.h"
  12. #include "debug.h"
  13. #include "dmusic32.h"
  14. #include "dm32p.h"
  15. // Globals
  16. //
  17. // Dll's hModule
  18. //
  19. HMODULE g_hModule = NULL;
  20. extern "C" BOOL PASCAL dmthunk_ThunkConnect32(LPCSTR pszDll16, LPCSTR pszDll32, HINSTANCE hinst, DWORD dwReason);
  21. static CONST TCHAR pszDll16[] = "DMUSIC16.DLL";
  22. static CONST TCHAR pszDll32[] = "DMUSIC32.DLL";
  23. #ifdef DBG
  24. static char* aszReasons[] =
  25. {
  26. "DLL_PROCESS_DETACH",
  27. "DLL_PROCESS_ATTACH",
  28. "DLL_THREAD_ATTACH",
  29. "DLL_THREAD_DETACH"
  30. };
  31. const DWORD nReasons = (sizeof(aszReasons) / sizeof(char*));
  32. #endif
  33. // Standard Win32 DllMain
  34. //
  35. BOOL APIENTRY DllMain(HINSTANCE hModule,
  36. DWORD dwReason,
  37. void *lpReserved)
  38. {
  39. OSVERSIONINFO osvi;
  40. HANDLE ph;
  41. static int nReferenceCount = 0;
  42. #ifdef DBG
  43. if (dwReason < nReasons)
  44. {
  45. Trace(2, "DllMain: %s\n", (LPSTR)aszReasons[dwReason]);
  46. }
  47. else
  48. {
  49. Trace(2, "DllMain: Unknown dwReason <%u>\n", dwReason);
  50. }
  51. #endif
  52. switch(dwReason)
  53. {
  54. case DLL_PROCESS_ATTACH:
  55. if (++nReferenceCount == 1)
  56. {
  57. #ifdef DBG
  58. DebugInit();
  59. #endif
  60. if (!DisableThreadLibraryCalls(hModule))
  61. {
  62. Trace(0, "DisableThreadLibraryCalls failed.\n");
  63. }
  64. if (!OpenMMDEVLDR())
  65. {
  66. Trace(0, "OpenMMDEVLDR failed.\n");
  67. }
  68. }
  69. break;
  70. case DLL_PROCESS_DETACH:
  71. if (--nReferenceCount == 0)
  72. {
  73. Trace(1, "Last process detach\n");
  74. CloseMMDEVLDR();
  75. }
  76. break;
  77. default:
  78. Trace(-1, "Got a non-process at/detach!\n");
  79. break;
  80. }
  81. if (dwReason == DLL_PROCESS_ATTACH)
  82. {
  83. g_hModule = hModule;
  84. osvi.dwOSVersionInfoSize = sizeof(osvi);
  85. GetVersionEx(&osvi);
  86. if (osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
  87. {
  88. return FALSE;
  89. }
  90. }
  91. if (!dmthunk_ThunkConnect32(pszDll16, pszDll32, hModule, dwReason))
  92. {
  93. Trace(-1, "Could not connect to thunk layer! - not loading.\n");
  94. return FALSE;
  95. }
  96. return TRUE;
  97. }