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.

151 lines
4.5 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. break;
  70. }
  71. return TRUE;
  72. }
  73. //
  74. // Procedure for uninstalling this DLL (given an INF file). Note: this DLL
  75. // really should dynamically load setupapi.dll, to avoid its overhead all the
  76. // time.
  77. //
  78. void WINAPI
  79. UninstallW(
  80. HWND hwndStub,
  81. HINSTANCE hInstance,
  82. LPTSTR lpszCmdLine,
  83. int nCmdShow
  84. )
  85. {
  86. RUNDLLPROC pfnCheckAPI = UninstallW; // let compiler check the prototype
  87. if (!lpszCmdLine || lstrlen(lpszCmdLine) >= MAX_PATH)
  88. {
  89. return;
  90. }
  91. TCHAR szSure[200];
  92. LoadString(g_hInstance, IDS_SUREUNINST, szSure, ARRAYLEN(szSure));
  93. TCHAR szTitle[200];
  94. LoadString(g_hInstance, IDS_MSGTITLE, szTitle, ARRAYLEN(szTitle));
  95. if (MessageBox(hwndStub, szSure, szTitle, MB_YESNO | MB_ICONSTOP) != IDYES)
  96. {
  97. return;
  98. }
  99. HINF hinf = SetupOpenInfFile(
  100. lpszCmdLine, // should be the name of the inf
  101. NULL, // optional Version section CLASS info
  102. INF_STYLE_WIN4,
  103. NULL); // optional error line info
  104. if (INVALID_HANDLE_VALUE == hinf)
  105. {
  106. appDebugOut((DEB_ERROR,
  107. "SetupOpenInfFile failed, 0x%x\n",
  108. GetLastError()));
  109. return;
  110. }
  111. PVOID pContext = SetupInitDefaultQueueCallback(hwndStub);
  112. BOOL ret = SetupInstallFromInfSection(
  113. hwndStub, // optional, handle of a parent window
  114. hinf, // handle to the INF file
  115. TEXT("DefaultUninstall"), // section of the INF file to install
  116. SPINST_REGISTRY | SPINST_FILES, // which lines to install from section
  117. HKEY_CURRENT_USER, // optional, key for registry installs
  118. NULL, // optional, path for source files
  119. SP_COPY_FORCE_NEWER, // optional, specifies copy behavior
  120. SetupDefaultQueueCallback, // optional, specifies callback routine
  121. pContext, // optional, callback routine context
  122. NULL, // optional, device information set
  123. NULL); // optional, device info structure
  124. if (!ret)
  125. {
  126. appDebugOut((DEB_ERROR,
  127. "SetupInstallFromInfSection failed, 0x%x\n",
  128. GetLastError()));
  129. }
  130. SetupCloseInfFile(hinf);
  131. }