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.

154 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: dllmain.hxx
  7. //
  8. // Contents: DLL initialization entrypoint and global variables
  9. //
  10. // History: 4-Apr-95 BruceFo Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include <locale.h>
  16. #include <setupapi.h>
  17. #include "resource.h"
  18. #include "util.hxx"
  19. const TCHAR c_szShellIDList[] = CFSTR_SHELLIDLIST;
  20. //+--------------------------------------------------------------------------
  21. //
  22. // Function: DllMain
  23. //
  24. // Synopsis: Win32 DLL initialization function
  25. //
  26. // Arguments: [hInstance] - Handle to this dll
  27. // [dwReason] - Reason this function was called. Can be
  28. // Process/Thread Attach/Detach.
  29. //
  30. // Returns: BOOL - TRUE if no error. FALSE otherwise
  31. //
  32. // History: 4-Apr-95 BruceFo Created
  33. //
  34. //---------------------------------------------------------------------------
  35. extern "C"
  36. BOOL
  37. DllMain(
  38. HINSTANCE hInstance,
  39. DWORD dwReason,
  40. LPVOID lpReserved
  41. )
  42. {
  43. switch (dwReason)
  44. {
  45. case DLL_PROCESS_ATTACH:
  46. {
  47. #if DBG == 1
  48. InitializeDebugging();
  49. // SharingInfoLevel = DEB_ERROR | DEB_TRACE;
  50. SharingInfoLevel = DEB_ERROR;
  51. SetWin4AssertLevel(ASSRT_BREAK | ASSRT_MESSAGE);
  52. #endif // DBG == 1
  53. appDebugOut((DEB_TRACE, "shareui.dll: DllMain enter\n"));
  54. // Disable thread notification from OS
  55. DisableThreadLibraryCalls(hInstance);
  56. g_hInstance = hInstance;
  57. InitCommonControls(); // get up/down control
  58. setlocale(LC_CTYPE, ""); // set the C runtime library locale, for string operations
  59. g_cfHIDA = RegisterClipboardFormat(c_szShellIDList);
  60. // Determine the maximum number of users
  61. g_uiMaxUsers = IsWorkstationProduct()
  62. ? MAX_USERS_ON_WORKSTATION
  63. : MAX_USERS_ON_SERVER
  64. ;
  65. break;
  66. }
  67. case DLL_PROCESS_DETACH:
  68. appDebugOut((DEB_TRACE, "shareui.dll: DllMain leave\n"));
  69. #if DBG == 1
  70. UninitializeDebugging();
  71. #endif // DBG == 1
  72. break;
  73. }
  74. return TRUE;
  75. }
  76. //
  77. // Procedure for uninstalling this DLL (given an INF file). Note: this DLL
  78. // really should dynamically load setupapi.dll, to avoid its overhead all the
  79. // time.
  80. //
  81. void WINAPI
  82. UninstallW(
  83. HWND hwndStub,
  84. HINSTANCE hInstance,
  85. LPTSTR lpszCmdLine,
  86. int nCmdShow
  87. )
  88. {
  89. RUNDLLPROC pfnCheckAPI = UninstallW; // let compiler check the prototype
  90. if (!lpszCmdLine || lstrlen(lpszCmdLine) >= MAX_PATH)
  91. {
  92. return;
  93. }
  94. TCHAR szSure[200];
  95. LoadString(g_hInstance, IDS_SUREUNINST, szSure, ARRAYLEN(szSure));
  96. TCHAR szTitle[200];
  97. LoadString(g_hInstance, IDS_MSGTITLE, szTitle, ARRAYLEN(szTitle));
  98. if (MessageBox(hwndStub, szSure, szTitle, MB_YESNO | MB_ICONSTOP) != IDYES)
  99. {
  100. return;
  101. }
  102. HINF hinf = SetupOpenInfFile(
  103. lpszCmdLine, // should be the name of the inf
  104. NULL, // optional Version section CLASS info
  105. INF_STYLE_WIN4,
  106. NULL); // optional error line info
  107. if (INVALID_HANDLE_VALUE == hinf)
  108. {
  109. appDebugOut((DEB_ERROR,
  110. "SetupOpenInfFile failed, 0x%x\n",
  111. GetLastError()));
  112. return;
  113. }
  114. PVOID pContext = SetupInitDefaultQueueCallback(hwndStub);
  115. BOOL ret = SetupInstallFromInfSection(
  116. hwndStub, // optional, handle of a parent window
  117. hinf, // handle to the INF file
  118. TEXT("DefaultUninstall"), // section of the INF file to install
  119. SPINST_REGISTRY | SPINST_FILES, // which lines to install from section
  120. HKEY_CURRENT_USER, // optional, key for registry installs
  121. NULL, // optional, path for source files
  122. SP_COPY_FORCE_NEWER, // optional, specifies copy behavior
  123. SetupDefaultQueueCallback, // optional, specifies callback routine
  124. pContext, // optional, callback routine context
  125. NULL, // optional, device information set
  126. NULL); // optional, device info structure
  127. if (!ret)
  128. {
  129. appDebugOut((DEB_ERROR,
  130. "SetupInstallFromInfSection failed, 0x%x\n",
  131. GetLastError()));
  132. }
  133. SetupCloseInfFile(hinf);
  134. }