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.

310 lines
7.3 KiB

  1. /*************************************************************************
  2. **
  3. **
  4. ** File : RWExeMain.cpp
  5. ** Product :
  6. ** Date : 05/07/97
  7. ** Author : Suresh Krishnan
  8. **
  9. ** Registration Wizard Exe programs main file
  10. ** The Exe version of Registration Wizard is implemented using the Active X
  11. ** component
  12. **
  13. *************************************************************************/
  14. #define STRICT
  15. #include <windows.h>
  16. #include <windowsx.h>
  17. #ifdef WIN16
  18. #include <ole2.h>
  19. #include <compobj.h>
  20. #include <dispatch.h>
  21. #include <variant.h>
  22. #include <olenls.h>
  23. #include <commdlg.h>
  24. #endif
  25. #include <initguid.h>
  26. #include "RWInterface.h"
  27. #include "RWExeMain.h"
  28. #include "resource.h"
  29. // Globals
  30. HINSTANCE g_hinst; // Instance of application
  31. HWND g_hwnd; // Toplevel window handle
  32. TCHAR g_szNotFound[STR_LEN];
  33. TCHAR g_szError[STR_LEN];
  34. #define INVOKDE_REGISTRATION 1
  35. #define INVOKE_TRANSFER 2
  36. #define INVOKE_ERROR 3
  37. #define chSpace 32
  38. int ProcessCmdLine(LPTSTR lpCmd)
  39. {
  40. int iC=0;
  41. int iExit=1;
  42. LPTSTR szCurr = lpCmd;
  43. if (lpCmd == NULL || lpCmd[0] == 0)
  44. {
  45. return INVOKE_ERROR;
  46. }
  47. while (*szCurr == chSpace)
  48. {
  49. szCurr = CharNext(szCurr);
  50. }
  51. if (*szCurr != '/' && *szCurr != '-') {
  52. return INVOKE_ERROR ;
  53. }
  54. szCurr = CharNext(szCurr);
  55. if (*szCurr == 'I' || *szCurr == 'i') {
  56. return INVOKDE_REGISTRATION ;
  57. }
  58. if (*szCurr == 'T' || *szCurr == 't') {
  59. return INVOKE_TRANSFER ;
  60. }
  61. return INVOKE_ERROR;
  62. }
  63. /*
  64. * WinMain
  65. *
  66. * Purpose:
  67. * Main entry point of application. Should register the app class
  68. * if a previous instance has not done so and do any other one-time
  69. * initializations.
  70. *
  71. */
  72. /*
  73. int _tWinMain ( HINSTANCE hinst,
  74. HINSTANCE hinstPrev,
  75. LPTSTR lpCmdLine,
  76. int nCmdShow)
  77. */
  78. int APIENTRY WinMain (HINSTANCE hinst,
  79. HINSTANCE hinstPrev,
  80. LPSTR lpCmdLine,
  81. int nCmdShow)
  82. {
  83. MSG msg;
  84. static IRegWizCtrl FAR* pRegWiz = NULL;
  85. HRESULT hr;
  86. LPUNKNOWN punk;
  87. // It is recommended that all OLE applications set
  88. // their message queue size to 96. This improves the capacity
  89. // and performance of OLE's LRPC mechanism.
  90. int cMsg = 96; // Recommend msg queue size for OLE
  91. while (cMsg && !SetMessageQueue(cMsg)) // take largest size we can get.
  92. cMsg -= 8;
  93. if (!cMsg)
  94. return -1; // ERROR: we got no message queue
  95. LoadString(hinst, IDS_RWNOTFOUND, g_szNotFound, STR_LEN);
  96. LoadString(hinst, IDS_ERROR, g_szError, STR_LEN);
  97. if (!hinstPrev)
  98. if (!InitApplication(hinst))
  99. return (FALSE);
  100. if(OleInitialize(NULL) != NOERROR)
  101. return FALSE;
  102. if (!InitInstance(hinst, nCmdShow))
  103. return (FALSE);
  104. hr = CoCreateInstance(CLSID_RegWizCtrl, NULL, CLSCTX_INPROC_SERVER,
  105. IID_IUnknown, (void FAR* FAR*)&punk);
  106. if (FAILED(hr)) {
  107. MessageBox(NULL,g_szNotFound , g_szError, MB_OK);
  108. return 0L;
  109. }
  110. hr = punk->QueryInterface(IID_IRegWizCtrl , (void FAR* FAR*)&pRegWiz);
  111. if (FAILED(hr))
  112. {
  113. MessageBox(NULL, TEXT("QueryInterface(IID_IHello)"), g_szError, MB_OK);
  114. punk->Release();
  115. return 0L;
  116. }
  117. #ifndef _UNICODE
  118. hr = pRegWiz->InvokeRegWizard(ConvertToUnicode(lpCmdLine));
  119. #else
  120. hr = pRegWiz->InvokeRegWizard(lpCmdLine);
  121. #endif
  122. /*
  123. int iStatus = ProcessCmdLine(lpCmdLine);
  124. switch(iStatus )
  125. {
  126. case INVOKDE_REGISTRATION :
  127. #ifndef _UNICODE
  128. hr = pRegWiz->InvokeRegWizard(ConvertToUnicode(lpCmdLine));
  129. #else
  130. hr = pRegWiz->InvokeRegWizard(lpCmdLine);
  131. #endif
  132. break;
  133. case INVOKE_TRANSFER :
  134. #ifndef _UNICODE
  135. hr = pRegWiz->TransferRegWizInformation(ConvertToUnicode(lpCmdLine));
  136. #else
  137. hr = pRegWiz->TransferRegWizInformation(lpCmdLine);
  138. #endif
  139. default:
  140. break;
  141. }
  142. */
  143. // ConvertToUnicode("/i \"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\"") );
  144. OleUninitialize();
  145. if(SUCCEEDED(hr))
  146. return NO_ERROR;
  147. else
  148. return 1;
  149. //return (msg.wParam); // Returns the value from PostQuitMessage
  150. }
  151. /*
  152. * InitApplication
  153. *
  154. * Purpose:
  155. * Registers window class
  156. *
  157. * Parameters:
  158. * hinst hInstance of application
  159. *
  160. * Return Value:
  161. * TRUE if initialization succeeded, FALSE otherwise.
  162. */
  163. BOOL InitApplication (HINSTANCE hinst)
  164. {
  165. WNDCLASS wc;
  166. wc.style = CS_DBLCLKS;
  167. wc.lpfnWndProc = MainWndProc;
  168. wc.cbClsExtra = 0;
  169. wc.cbWndExtra = 0;
  170. wc.hInstance = hinst;
  171. wc.hIcon =0; // LoadIcon(hinst, TEXT("ControlIcon"));
  172. wc.hCursor =0; // LoadCursor(NULL, IDC_ARROW);
  173. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  174. wc.lpszMenuName = NULL ;//TEXT("");
  175. wc.lpszClassName = TEXT("RegistrationWizard");
  176. return RegisterClass(&wc);
  177. }
  178. /*
  179. * InitInstance
  180. *
  181. * Purpose:
  182. * Creates and shows main window
  183. *
  184. * Parameters:
  185. * hinst hInstance of application
  186. * nCmdShow specifies how window is to be shown
  187. *
  188. * Return Value:
  189. * TRUE if initialization succeeded, FALSE otherwise.
  190. */
  191. BOOL InitInstance (HINSTANCE hinst, int nCmdShow)
  192. {
  193. g_hinst = hinst;
  194. return TRUE;
  195. }
  196. /*
  197. * MainWndProc
  198. *
  199. * Purpose:
  200. * Window procedure for main window
  201. *
  202. */
  203. LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  204. {
  205. switch (msg)
  206. {
  207. case WM_DESTROY:
  208. PostQuitMessage(0);
  209. break;
  210. default:
  211. return DefWindowProc(hwnd, msg, wParam, lParam);
  212. }
  213. return NULL;
  214. }
  215. /*
  216. * DisplayError
  217. *
  218. * Purpose:
  219. * Obtains Rich Error Information about the automation error from
  220. * the IErrorInfo interface.
  221. *
  222. */
  223. void DisplayError(IRegWizCtrl FAR* phello)
  224. {
  225. IErrorInfo FAR* perrinfo;
  226. BSTR bstrDesc;
  227. HRESULT hr;
  228. ISupportErrorInfo FAR* psupporterrinfo;
  229. hr = phello->QueryInterface(IID_ISupportErrorInfo, (LPVOID FAR*)&psupporterrinfo);
  230. if (FAILED(hr))
  231. {
  232. MessageBox(NULL, TEXT("QueryInterface(IID_ISupportErrorInfo)"), g_szError, MB_OK);
  233. return;
  234. }
  235. hr = psupporterrinfo->InterfaceSupportsErrorInfo(IID_IRegWizCtrl);
  236. if (hr != NOERROR)
  237. {
  238. psupporterrinfo->Release();
  239. return;
  240. }
  241. psupporterrinfo->Release();
  242. // In this example only the error description is obtained and displayed.
  243. // See the IErrorInfo interface for other information that is available.
  244. hr = GetErrorInfo(0, &perrinfo);
  245. if (FAILED(hr))
  246. return;
  247. hr = perrinfo->GetDescription(&bstrDesc);
  248. if (FAILED(hr))
  249. {
  250. perrinfo->Release();
  251. return;
  252. }
  253. MessageBox(NULL, FROM_OLE_STRING(bstrDesc), g_szError, MB_OK);
  254. SysFreeString(bstrDesc);
  255. }
  256. #ifdef WIN32
  257. #ifndef UNICODE
  258. char* ConvertToAnsi(OLECHAR FAR* szW)
  259. {
  260. static char achA[STRCONVERT_MAXLEN];
  261. WideCharToMultiByte(CP_ACP, 0, szW, -1, achA, STRCONVERT_MAXLEN, NULL, NULL);
  262. return achA;
  263. }
  264. OLECHAR* ConvertToUnicode(char FAR* szA)
  265. {
  266. static OLECHAR achW[STRCONVERT_MAXLEN];
  267. MultiByteToWideChar(CP_ACP, 0, szA, -1, achW, STRCONVERT_MAXLEN);
  268. return achW;
  269. }
  270. #endif
  271. #endif