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.

132 lines
3.1 KiB

  1. // WinXPChk.cpp : A small program runs inside IExpress package to check if the current
  2. // platform is Windows XP. If so, run home network wizard directly. If not, continue
  3. // the rest of IExpress installation by installing the specified INF file.
  4. //
  5. // Usage: WinXPChk hnwcli.inf,DefaultInstall
  6. #include "stdafx.h"
  7. #include <shlwapi.h>
  8. typedef UINT (CALLBACK* LPFNDLLFUNC1)(HWND,HINSTANCE, LPSTR, int);
  9. void ShowErrMsg(LPSTR msg)
  10. {
  11. LPVOID lpMsgBuf;
  12. FormatMessage(
  13. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  14. FORMAT_MESSAGE_FROM_SYSTEM |
  15. FORMAT_MESSAGE_IGNORE_INSERTS,
  16. NULL,
  17. GetLastError(),
  18. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  19. (LPTSTR) &lpMsgBuf,
  20. 0,
  21. NULL
  22. );
  23. // Process any inserts in lpMsgBuf.
  24. // Display the string.
  25. MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
  26. // Free the buffer.
  27. LocalFree( lpMsgBuf );
  28. }
  29. int APIENTRY WinMain(HINSTANCE hInstance,
  30. HINSTANCE hPrevInstance,
  31. LPSTR lpCmdLine,
  32. int nCmdShow)
  33. {
  34. DWORD dwVersion;
  35. dwVersion = GetVersion();
  36. HINSTANCE hDLL; // Handle to DLL
  37. LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
  38. UINT uReturnVal = 0;
  39. if (LOBYTE(LOWORD(dwVersion)) == 5 && HIBYTE(LOWORD(dwVersion)) >= 1)
  40. //if (IsOS(OS_WHISTLERORGREATER))
  41. {
  42. // It is an XP box, run home network wizard directly.
  43. hDLL = LoadLibrary("hnetwiz.dll");
  44. if (hDLL != NULL)
  45. {
  46. lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "HomeNetWizardRunDll");
  47. if (!lpfnDllFunc1)
  48. {
  49. // handle the error
  50. ShowErrMsg("HomeNetWizardRunDll");
  51. FreeLibrary(hDLL);
  52. return -1;
  53. }
  54. else
  55. {
  56. // call the function
  57. uReturnVal = lpfnDllFunc1(NULL, hInstance, lpCmdLine, nCmdShow);
  58. FreeLibrary(hDLL);
  59. return uReturnVal;
  60. }
  61. }
  62. else
  63. {
  64. ShowErrMsg("hnetwiz.dll");
  65. return -1;
  66. }
  67. }
  68. else
  69. {
  70. // check to see if upnpui.dll is installed. Use different INF files depending on its
  71. // presence in the system.
  72. TCHAR szDllPath[MAX_PATH];
  73. LPSTR szParam = TEXT("NoUPnP.inf,DefaultInstall");;
  74. if (GetSystemDirectory(szDllPath, MAX_PATH) != 0)
  75. {
  76. PathAppend(szDllPath, TEXT("upnpui.dll"));
  77. if (PathFileExists(szDllPath))
  78. {
  79. szParam = TEXT("HasUPnP.inf,DefaultInstall");
  80. }
  81. }
  82. hDLL = LoadLibrary("advpack.dll");
  83. if (hDLL != NULL)
  84. {
  85. lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "LaunchINFSection");
  86. if (!lpfnDllFunc1)
  87. {
  88. // handle the error
  89. ShowErrMsg("LaunchINFSection");
  90. FreeLibrary(hDLL);
  91. return -1;
  92. }
  93. else
  94. {
  95. // call the function
  96. uReturnVal = lpfnDllFunc1(NULL, hInstance, szParam, nCmdShow);
  97. FreeLibrary(hDLL);
  98. return uReturnVal;
  99. }
  100. }
  101. else
  102. {
  103. ShowErrMsg("advpack.dll");
  104. return -1;
  105. }
  106. }
  107. return 0;
  108. }