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.

143 lines
3.7 KiB

  1. #define NOATOM
  2. #define NOCOMM
  3. #define NODEFERWINDOWPOS
  4. #define NODRIVERS
  5. #define NOEXTDEVMODEPROPSHEET
  6. #define NOIME
  7. #define NOKANJI
  8. #define NOMDI
  9. #define NOLOGERROR
  10. #define NOMCX
  11. #define NOPROFILER
  12. #define NOSCALABLEFONT
  13. #define NOSERVICE
  14. #define NOSOUND
  15. #define NOWINDOWSX
  16. #define NOENHMETAFILE
  17. // Ignore header files that have to be read that we don't want.
  18. #define _WINNETWK_
  19. //#define _WINREG_
  20. #define _WINCON_
  21. #define VER_H
  22. //#define _OLE2_H_
  23. //#define WIN32_LEAN_AND_MEAN
  24. #include <windows.h>
  25. int __cdecl _purecall(void)
  26. {
  27. return -1;
  28. }
  29. typedef void (__cdecl *_PVFV)(void);
  30. #if defined(_M_IX86)
  31. int __cdecl atexit(_PVFV func)
  32. {
  33. return -1;
  34. }
  35. #endif
  36. #pragma data_seg(".text", "CODE")
  37. static const char txtHHCtrl[] = "hhctrl.ocx";
  38. static const char txtDoWinMain[] = "doWinMain";
  39. static const CLSID CLSID_HHCtrl = {0xadb880a6,0xd8ff,0x11cf,{0x93,0x77,0x00,0xaa,0x00,0x3b,0x7a,0x11}};
  40. static const char txtStringGuid[] = "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}";
  41. static const char txtInProc[] = "CLSID\\%s\\InprocServer32";
  42. #pragma data_seg()
  43. //=--------------------------------------------------------------------------=
  44. // StringFromGuidA
  45. //=--------------------------------------------------------------------------=
  46. // returns an ANSI string from a CLSID or GUID
  47. //
  48. // Parameters:
  49. // REFIID - [in] clsid to make string out of.
  50. // LPSTR - [in/out] buffer in which to place resultant GUID.
  51. //
  52. // Output:
  53. // int - number of chars written out.
  54. //
  55. // Notes:
  56. //
  57. int StringFromGuidA( CLSID riid, LPSTR pszBuf )
  58. {
  59. return wsprintf( (char*) pszBuf,
  60. txtStringGuid,
  61. riid.Data1, riid.Data2, riid.Data3,
  62. riid.Data4[0], riid.Data4[1], riid.Data4[2], riid.Data4[3],
  63. riid.Data4[4], riid.Data4[5], riid.Data4[6], riid.Data4[7]);
  64. }
  65. #define GUID_STR_LEN 40
  66. //=--------------------------------------------------------------------------=
  67. // GetRegisteredLocation
  68. //=--------------------------------------------------------------------------=
  69. // Returns the registered location of an inproc server given the CLSID
  70. //
  71. // HKEY_CLASSES_ROOT\CLSID\<CLSID>\InprocServer32 = <path to local server>
  72. //
  73. // Parameters:
  74. // REFCLSID - [in] CLSID of the object
  75. // LPTSTR - [in/out] Pathname
  76. //
  77. // Output:
  78. // BOOL - FALSE means couldn't find it
  79. BOOL GetRegisteredLocation( CLSID riid, LPTSTR pszPathname )
  80. {
  81. BOOL bReturn = FALSE;
  82. HKEY hKey = NULL;
  83. char szGuidStr[GUID_STR_LEN];
  84. char szScratch[MAX_PATH];
  85. if( !StringFromGuidA( riid, szGuidStr ) )
  86. return FALSE;
  87. wsprintf( szScratch, txtInProc, szGuidStr );
  88. if( RegOpenKeyEx( HKEY_CLASSES_ROOT, szScratch, 0, KEY_READ, &hKey ) == ERROR_SUCCESS ) {
  89. DWORD dwSize = MAX_PATH;
  90. if( RegQueryValueEx( hKey, "", 0, 0, szScratch, &dwSize ) == ERROR_SUCCESS ) {
  91. lstrcpy( pszPathname, szScratch );
  92. bReturn = TRUE;
  93. }
  94. }
  95. if( hKey )
  96. RegCloseKey( hKey );
  97. return bReturn;
  98. }
  99. FARPROC pDoWinMain;
  100. int doWinMain(HINSTANCE hinstApp, LPSTR lpszCmdLine);
  101. int WINAPI WinMain(HINSTANCE hinstCur, HINSTANCE hinstPrev, LPSTR lpszCmdLine,
  102. int iCmdShow)
  103. {
  104. TCHAR szHHCtrl[MAX_PATH];
  105. HMODULE hmodHHCtrl;
  106. // if we have a registered location for hhctrl.ocx then use it
  107. // otherwise load the one on the path
  108. if( !GetRegisteredLocation( CLSID_HHCtrl, szHHCtrl ) )
  109. lstrcpy( szHHCtrl, txtHHCtrl );
  110. hmodHHCtrl = (HMODULE) LoadLibrary( szHHCtrl );
  111. if( !hmodHHCtrl )
  112. hmodHHCtrl = (HMODULE) LoadLibrary( txtHHCtrl );
  113. if( hmodHHCtrl ) {
  114. if( pDoWinMain = GetProcAddress( hmodHHCtrl, txtDoWinMain ) ) {
  115. int iReturn = (int)pDoWinMain(hinstCur, lpszCmdLine);
  116. FreeLibrary( hmodHHCtrl );
  117. return iReturn;
  118. }
  119. }
  120. return -1;
  121. }