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.

200 lines
5.0 KiB

  1. #include "syncapp.h"
  2. #ifndef WIN32
  3. #include <w32sys.h> // for IsPEFormat definition
  4. #endif
  5. static TCHAR const g_szAppName [] = TEXT("SYNCAPP") ;
  6. static TCHAR const c_szDLL[] = TEXT("SYNCUI.DLL");
  7. #ifdef UNICODE
  8. # define BRIEFCASE_CREATE_ENTRY "Briefcase_CreateW"
  9. #else
  10. # define BRIEFCASE_CREATE_ENTRY "Briefcase_Create"
  11. #endif
  12. static CHAR const c_szFunction[] = BRIEFCASE_CREATE_ENTRY; // Lib entry point (never UNICODE)
  13. static HINSTANCE hInst;
  14. static HICON g_hIcon;
  15. static HINSTANCE g_hModule;
  16. static RUNDLLPROC g_lpfnCommand;
  17. static HWND g_hwndStub;
  18. static TCHAR s_szRunDLL32[] = TEXT("SYNCAPP.EXE ");
  19. static BOOL ParseCommand(void)
  20. {
  21. // Load the library and get the procedure address
  22. // Note that we try to get a module handle first, so we don't need
  23. // to pass full file names around
  24. //
  25. g_hModule = GetModuleHandle(c_szDLL);
  26. if (g_hModule)
  27. {
  28. TCHAR szName[MAXPATHLEN];
  29. GetModuleFileName(g_hModule, szName, ARRAYSIZE(szName));
  30. LoadLibrary(szName);
  31. }
  32. else
  33. {
  34. g_hModule = LoadLibrary(c_szDLL);
  35. if ((UINT_PTR)g_hModule <= 32)
  36. {
  37. return(FALSE);
  38. }
  39. }
  40. g_lpfnCommand = (RUNDLLPROC)GetProcAddress(g_hModule, c_szFunction);
  41. if (!g_lpfnCommand)
  42. {
  43. FreeLibrary(g_hModule);
  44. return(FALSE);
  45. }
  46. return(TRUE);
  47. }
  48. LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
  49. {
  50. switch(iMessage)
  51. {
  52. case WM_CREATE:
  53. g_hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_DEFAULT));
  54. break;
  55. case WM_DESTROY:
  56. break;
  57. default:
  58. return DefWindowProc(hWnd, iMessage, wParam, lParam) ;
  59. break;
  60. }
  61. return 0L;
  62. }
  63. static BOOL InitStubWindow(HINSTANCE hInst, HINSTANCE hPrevInstance)
  64. {
  65. WNDCLASS wndclass;
  66. if (!hPrevInstance)
  67. {
  68. wndclass.style = 0 ;
  69. wndclass.lpfnWndProc = WndProc ;
  70. wndclass.cbClsExtra = 0 ;
  71. wndclass.cbWndExtra = 0 ;
  72. wndclass.hInstance = hInst ;
  73. wndclass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_DEFAULT)) ;
  74. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  75. wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  76. wndclass.lpszMenuName = NULL ;
  77. wndclass.lpszClassName = g_szAppName ;
  78. if (!RegisterClass(&wndclass))
  79. {
  80. return(FALSE);
  81. }
  82. }
  83. g_hwndStub = CreateWindow(g_szAppName, TEXT(""), 0,
  84. 0, 0, 0, 0, NULL, NULL, hInst, NULL);
  85. return(g_hwndStub != NULL);
  86. }
  87. static void CleanUp(void)
  88. {
  89. DestroyWindow(g_hwndStub);
  90. FreeLibrary(g_hModule);
  91. }
  92. int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszWinMainCmdLine, int nCmdShow)
  93. {
  94. LPTSTR lpszCmdLine;
  95. hInst = hInstance;
  96. //
  97. // The command line passed to WinMain is always ANSI, so for UNICODE
  98. // builds we need to ask for the command line in UNICODE
  99. //
  100. #ifdef UNICODE
  101. //
  102. // Since the command line returned from GetCommandLine includes
  103. // argv[0], but the one passed to Winmain does not, we have
  104. // to strip argv[0] in order to be equivalent
  105. //
  106. lpszCmdLine = GetCommandLine();
  107. //
  108. // Skip past program name (first token in command line).
  109. // Check for and handle quoted program name.
  110. //
  111. if ( *lpszCmdLine == '\"' )
  112. {
  113. //
  114. // Scan, and skip over, subsequent characters until
  115. // another double-quote or a null is encountered.
  116. //
  117. while ( *++lpszCmdLine && (*lpszCmdLine
  118. != '\"') );
  119. //
  120. // If we stopped on a double-quote (usual case), skip
  121. // over it.
  122. //
  123. if ( *lpszCmdLine == '\"' )
  124. lpszCmdLine++;
  125. }
  126. else
  127. {
  128. while (*lpszCmdLine > ' ')
  129. lpszCmdLine++;
  130. }
  131. //
  132. // Skip past any white space preceeding the second token.
  133. //
  134. while (*lpszCmdLine && (*lpszCmdLine <= ' '))
  135. {
  136. lpszCmdLine++;
  137. }
  138. #else
  139. lpszCmdLine = lpszWinMainCmdLine;
  140. #endif
  141. // turn off critical error stuff
  142. SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
  143. if (!ParseCommand())
  144. {
  145. goto Error0;
  146. }
  147. if (!InitStubWindow(hInstance, hPrevInstance))
  148. {
  149. goto Error1;
  150. }
  151. (*g_lpfnCommand)(g_hwndStub, hInstance, lpszCmdLine, nCmdShow);
  152. Error1:
  153. CleanUp();
  154. Error0:
  155. return(FALSE);
  156. }