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.

204 lines
5.4 KiB

  1. // File: setupdd.cpp
  2. // The code to install the NM display driver for Windows NT.
  3. // TODO: NM-specific HRESULT codes
  4. #include "precomp.h"
  5. #include "resource.h"
  6. #ifdef NMDLL_HACK
  7. inline HINSTANCE GetInstanceHandle() { return g_hInst; }
  8. #endif
  9. const TCHAR g_pcszDisplayCPLName[] = TEXT("DESK.CPL");
  10. const CHAR g_pcszInstallDriverAPIName[] = "InstallGraphicsDriver";
  11. const WCHAR g_pcwszDefaultModelName[] = L"Microsoft NetMeeting graphics driver";
  12. const WCHAR g_pcwszDefaultINFName[] = L"MNMDD.INF";
  13. // Maxmimum size of the model name string
  14. const int NAME_BUFFER_SIZE = 128;
  15. // Prototype for the function installed by the Display CPL
  16. typedef DWORD (*PFNINSTALLGRAPHICSDRIVER)(
  17. HWND hwnd,
  18. LPCWSTR pszSourceDirectory,
  19. LPCWSTR pszModel,
  20. LPCWSTR pszInf
  21. );
  22. /* C A N I N S T A L L N T D I S P L A Y D R I V E R */
  23. /*-------------------------------------------------------------------------
  24. %%Function: CanInstallNTDisplayDriver
  25. This function determines whether the entry point for installing the
  26. NT display driver is availalble (i.e. NT 4.0 SP3 or later).
  27. -------------------------------------------------------------------------*/
  28. HRESULT CanInstallNTDisplayDriver(void)
  29. {
  30. if (!IsWindowsNT())
  31. {
  32. return E_FAIL;
  33. }
  34. // We verify that the major version number is exactly 4 and either
  35. // the minor version number is greater than 0 or the service pack
  36. // number (which is stored in the high byte of the low word of the
  37. // CSD version) is 3 or greater.
  38. OSVERSIONINFO osvi;
  39. osvi.dwOSVersionInfoSize = sizeof(osvi);
  40. if (FALSE == ::GetVersionEx(&osvi))
  41. {
  42. ERROR_OUT(("CanInstallNTDisplayDriver: GetVersionEx failed"));
  43. return E_FAIL;
  44. }
  45. HRESULT hr = E_FAIL;
  46. if (4 == osvi.dwMajorVersion)
  47. {
  48. if (0 == osvi.dwMinorVersion)
  49. {
  50. RegEntry re(NT_WINDOWS_SYSTEM_INFO_KEY, HKEY_LOCAL_MACHINE, FALSE);
  51. DWORD dwCSDVersion = re.GetNumber(REGVAL_NT_CSD_VERSION, 0);
  52. if (3 <= HIBYTE(LOWORD(dwCSDVersion)))
  53. {
  54. // This is NT 4.0, SP 3 or later
  55. hr = S_OK;
  56. }
  57. }
  58. else
  59. {
  60. // We assume that any future version of Windows NT 4.x (x > 0)
  61. // will support this.
  62. hr = S_OK;
  63. }
  64. }
  65. return hr;
  66. }
  67. /* I N S T A L L A P P S H A R I N G D D */
  68. /*-------------------------------------------------------------------------
  69. %%Function: InstallAppSharingDD
  70. This function attempts to install the NT display driver.
  71. If it succeeds the machine MUST BE RESTARTED before it can be used.
  72. -------------------------------------------------------------------------*/
  73. HRESULT InstallAppSharingDD(HWND hwnd)
  74. {
  75. HRESULT hr;
  76. CUSTRING custrPath;
  77. TCHAR szDir[MAX_PATH];
  78. LPWSTR pwszSourcePath = NULL;
  79. LPWSTR pwszSourcePathEnd;
  80. WCHAR pwszModelNameBuffer[NAME_BUFFER_SIZE];
  81. LPCWSTR pcwszModelName;
  82. WCHAR pwszINFNameBuffer[MAX_PATH];
  83. LPCWSTR pcwszINFName;
  84. PFNINSTALLGRAPHICSDRIVER pfnInstallGraphicsDriver;
  85. // REVIEW: Need NM-specific HRESULTS for all of these
  86. if (!IsWindowsNT())
  87. {
  88. return E_FAIL;
  89. }
  90. if (!CanInstallNTDisplayDriver())
  91. {
  92. return E_FAIL;
  93. }
  94. // The driver files are located in the NM directory.
  95. if (!GetInstallDirectory(szDir))
  96. {
  97. ERROR_OUT(("GetInstallDirectory() fails"));
  98. return E_FAIL;
  99. }
  100. // Convert the install directory to Unicode, if necessary
  101. custrPath.AssignString(szDir);
  102. pwszSourcePath = custrPath;
  103. if (NULL == pwszSourcePath)
  104. {
  105. ERROR_OUT(("AnsiToUnicode() fails"));
  106. return E_FAIL;
  107. }
  108. // Strip the trailing backslash that GetInstallDirectory appends
  109. pwszSourcePathEnd = pwszSourcePath + lstrlenW(pwszSourcePath);
  110. // Handle X:\, just to be safe
  111. if (pwszSourcePathEnd - pwszSourcePath > 3)
  112. {
  113. ASSERT(L'\\' == *(pwszSourcePathEnd - 1));
  114. *--pwszSourcePathEnd = L'\0';
  115. }
  116. // Read the model name string from the resource file
  117. if (0 != ::LoadStringW(::GetInstanceHandle(), IDS_NMDD_DISPLAYNAME,
  118. pwszModelNameBuffer, CCHMAX(pwszModelNameBuffer)))
  119. {
  120. pcwszModelName = pwszModelNameBuffer;
  121. }
  122. else
  123. {
  124. ERROR_OUT(("LoadStringW() fails, err=%lu", GetLastError()));
  125. pcwszModelName = g_pcwszDefaultModelName;
  126. }
  127. // Read the INF name string from the resource file
  128. if (0 < ::LoadStringW(::GetInstanceHandle(),
  129. IDS_NMDD_INFNAME, pwszINFNameBuffer, CCHMAX(pwszINFNameBuffer)))
  130. {
  131. pcwszINFName = pwszINFNameBuffer;
  132. }
  133. else
  134. {
  135. ERROR_OUT(("LoadStringW() fails, err=%lu", GetLastError()));
  136. pcwszINFName = g_pcwszDefaultINFName;
  137. }
  138. // Get the entry point for display driver installation
  139. HMODULE hDll = NmLoadLibrary(g_pcszDisplayCPLName,TRUE);
  140. if (NULL == hDll)
  141. {
  142. ERROR_OUT(("NmLoadLibrary failed on %s", g_pcszDisplayCPLName));
  143. return E_FAIL;
  144. }
  145. pfnInstallGraphicsDriver = (PFNINSTALLGRAPHICSDRIVER)
  146. GetProcAddress(hDll, g_pcszInstallDriverAPIName);
  147. if (NULL == pfnInstallGraphicsDriver)
  148. {
  149. ERROR_OUT(("GetInstallDisplayDriverEntryPoint() fails"));
  150. hr = E_FAIL;
  151. }
  152. else
  153. { // Now we're set to call the actual installation function
  154. DWORD dwErr = (*pfnInstallGraphicsDriver)(hwnd,
  155. pwszSourcePath, pcwszModelName, pcwszINFName);
  156. if (0 != dwErr)
  157. {
  158. ERROR_OUT(("InstallGraphicsDriver() fails, err=%lu", dwErr));
  159. hr = E_FAIL;
  160. }
  161. else
  162. {
  163. WARNING_OUT(("InstallGraphicsDriver() succeeded"));
  164. hr = S_OK;
  165. }
  166. }
  167. // Cleanup
  168. ASSERT(NULL != hDll);
  169. FreeLibrary(hDll);
  170. return hr;
  171. }