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
2.8 KiB

  1. /*++=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. entry.c
  5. Abstract:
  6. Implements the WinMain() application entry point.
  7. Author:
  8. Paul M Midgen (pmidge) 07-June-2000
  9. Revision History:
  10. 07-June-2000 pmidge
  11. Created
  12. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--*/
  13. #include "common.h"
  14. void _SetCurrentDirectory(void);
  15. BOOL Initialize(void);
  16. void Terminate(void);
  17. int
  18. WINAPI
  19. WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  20. {
  21. _SetCurrentDirectory();
  22. DEBUG_INITIALIZE();
  23. DEBUG_ENTER((
  24. DBG_APP,
  25. rt_dword,
  26. "WinMain",
  27. "hInstance=%#x; hPrevInstance=%#x; cmdline=%s; cmdshow=%d",
  28. hInstance,
  29. hPrevInstance,
  30. szCmdLine,
  31. iCmdShow
  32. ));
  33. DWORD dwRet = ERROR_SUCCESS;
  34. HRESULT hr = S_OK;
  35. CFactory* pcf = NULL;
  36. IW3Spoof* pw3s = NULL;
  37. if( Initialize() )
  38. {
  39. hr = CFactory::Create(&pcf);
  40. if( FAILED(hr) )
  41. {
  42. DEBUG_TRACE(APP, ("failed to create class factory"));
  43. goto quit;
  44. }
  45. hr = pcf->CreateInstance(NULL, IID_IW3Spoof, (void**) &pw3s);
  46. if( FAILED(hr) )
  47. {
  48. DEBUG_TRACE(APP, ("failed to create w3spoof interface"));
  49. goto quit;
  50. }
  51. if( szCmdLine && strstr(szCmdLine, "register") )
  52. {
  53. goto quit;
  54. }
  55. pcf->Activate();
  56. pw3s->WaitForUnload();
  57. }
  58. else
  59. {
  60. DEBUG_TRACE(APP, ("application init failed."));
  61. }
  62. quit:
  63. DEBUG_TRACE(APP, ("starting final cleanup"));
  64. SAFETERMINATE(pcf);
  65. SAFERELEASE(pw3s);
  66. Terminate();
  67. DEBUG_LEAVE(dwRet);
  68. DEBUG_TERMINATE();
  69. return dwRet;
  70. }
  71. void
  72. _SetCurrentDirectory(void)
  73. {
  74. WCHAR path[MAX_PATH+1];
  75. memset((void*) path, 0L, MAX_PATH+1);
  76. if( GetModuleFileName(NULL, path, MAX_PATH) )
  77. {
  78. *(wcsrchr(path, L'\\')) = L'\0';
  79. SetCurrentDirectory(path);
  80. }
  81. }
  82. BOOL
  83. Initialize(void)
  84. {
  85. BOOL bRet = TRUE;
  86. DWORD dwRet = ERROR_SUCCESS;
  87. HRESULT hr = S_OK;
  88. WSADATA wsd = {0};
  89. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  90. if( SUCCEEDED(hr) )
  91. {
  92. if( (dwRet = WSAStartup(0x0202, &wsd)) != ERROR_SUCCESS )
  93. {
  94. DEBUG_TRACE(APP, ("WSAStartup failed: %d [%s]", dwRet, MapErrorToString(dwRet)));
  95. bRet = FALSE;
  96. }
  97. else
  98. {
  99. DEBUG_DUMPWSOCKSTATS(wsd);
  100. }
  101. }
  102. else
  103. {
  104. DEBUG_TRACE(APP, ("CoInitialize failed: %d [%s]", hr, MapHResultToString(hr)));
  105. bRet = FALSE;
  106. }
  107. return bRet;
  108. }
  109. void
  110. Terminate(void)
  111. {
  112. _GetRootKey(FALSE);
  113. WSACleanup();
  114. CoUninitialize();
  115. }