Changeset 801 in dev for branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp
- Timestamp:
- Feb 6, 2011, 9:47:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp
r800 r801 1 1 #include "stdafx.h" 2 2 #include <cstdint> 3 #include <cstring> 3 4 #include <process.h> 4 5 #include "OSVersion.h" … … 16 17 extern FARPROC alias__imp__InterlockedPushEntrySList; 17 18 extern FARPROC alias__imp__InterlockedPopEntrySList; 19 extern FARPROC alias__imp__GetModuleHandleW; 20 extern FARPROC alias__imp__GetStartupInfoW; 21 extern FARPROC alias__imp__GetEnvironmentStringsW; 22 extern FARPROC alias__imp__FreeEnvironmentStringsW; 18 23 extern void* TrapTableLast; 19 24 } // extern "C" … … 26 31 if (hmodKernel == nullptr) 27 32 { 28 hmodKernel = GetModuleHandle (TEXT("kernel32"));33 hmodKernel = GetModuleHandleA("kernel32"); 29 34 } 30 35 return hmodKernel; … … 65 70 #pragma warning(pop) 66 71 67 __declspec(naked) long __stdcallAlternative_InterlockedCompareExchange(long volatile*, long, long)72 __declspec(naked) long WINAPI Alternative_InterlockedCompareExchange(long volatile*, long, long) 68 73 { 69 74 __asm … … 83 88 } 84 89 90 HMODULE WINAPI Alternative_GetModuleHandleW(LPCWSTR moduleName) 91 { 92 HMODULE ret = nullptr; 93 auto size = std::wcslen(moduleName) + 1; 94 auto mbsSize = size * 2; 95 if (auto buffer = static_cast<LPSTR>(::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, mbsSize))) 96 { 97 if (::WideCharToMultiByte(CP_ACP, 0, moduleName, static_cast<int>(size), buffer, static_cast<int>(mbsSize), nullptr, nullptr) > 0) 98 { 99 ret = ::GetModuleHandleA(buffer); 100 } 101 ::HeapFree(::GetProcessHeap(), 0, buffer); 102 } 103 return ret; 104 } 105 106 // CRT用に最小限の実装 107 void WINAPI Alternative_GetStartupInfoW(LPSTARTUPINFOW psi) 108 { 109 STARTUPINFOA sia; 110 ::GetStartupInfoA(&sia); 111 112 *psi = STARTUPINFOW(); 113 psi->cb = sizeof *psi; 114 if (sia.dwFlags & STARTF_USESHOWWINDOW) 115 { 116 psi->dwFlags = STARTF_USESHOWWINDOW; 117 psi->wShowWindow = sia.wShowWindow; 118 } 119 } 120 121 LPWCH WINAPI Alternative_GetEnvironmentStringsW() 122 { 123 static WCHAR c[2]; 124 return c; 125 } 126 127 BOOL WINAPI Alternative_FreeEnvironmentStringsW(LPWCH) 128 { 129 return TRUE; 130 } 131 85 132 #define FUNCTION_INIT(name) \ 86 133 if (auto f = ::GetProcAddress(GetKernelModule(), #name)) { \ … … 88 135 } else { \ 89 136 alias__imp__ ## name = reinterpret_cast<FARPROC>(Alternative_ ## name); \ 137 } 138 139 #define FUNCTION_INIT_9X(name) \ 140 if (ActiveBasic::Common::Is9x()) { \ 141 alias__imp__ ## name = reinterpret_cast<FARPROC>(Alternative_ ## name); \ 142 } else { \ 143 alias__imp__ ## name = ::GetProcAddress(GetKernelModule(), #name); \ 90 144 } 91 145 … … 100 154 FUNCTION_INIT(DecodePointer); 101 155 FUNCTION_INIT(HeapSetInformation); 102 alias__imp__InitializeCriticalSectionAndSpinCount = 103 ActiveBasic::Common::Is9x() 104 ? reinterpret_cast<FARPROC>(Alternative_InitializeCriticalSectionAndSpinCount) 105 : ::GetProcAddress(GetKernelModule(), "InitializeCriticalSectionAndSpinCount"); 156 FUNCTION_INIT_9X(InitializeCriticalSectionAndSpinCount); 106 157 FUNCTION_INIT(InterlockedCompareExchange); 107 158 FUNCTION_INIT(IsProcessorFeaturePresent); 108 159 alias__imp__InterlockedPushEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPushEntrySList"); 109 160 alias__imp__InterlockedPopEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPopEntrySList"); 161 FUNCTION_INIT_9X(GetModuleHandleW); 162 FUNCTION_INIT_9X(GetStartupInfoW); 163 FUNCTION_INIT_9X(GetEnvironmentStringsW); 164 FUNCTION_INIT_9X(FreeEnvironmentStringsW); 110 165 111 166 ::VirtualProtect(&TrapTableFirst, … … 118 173 extern "C" 119 174 { 120 #ifdef _UNICODE 121 int wWinMainCRTStartup(); 122 #define tWinMainCRTStartup wWinMainCRTStartup 175 #ifdef _CONSOLE 176 # ifdef _UNICODE 177 int wmainCRTStartup(); 178 # define CRTStartup wmainCRTStartup 179 # else 180 int mainCRTStartup(); 181 # define CRTStartup mainCRTStartup 182 # endif 123 183 #else 124 int WinMainCRTStartup(); 125 #define tWinMainCRTStartup WinMainCRTStartup 184 # ifdef _UNICODE 185 int wWinMainCRTStartup(); 186 # define CRTStartup wWinMainCRTStartup 187 # else 188 int WinMainCRTStartup(); 189 # define CRTStartup WinMainCRTStartup 190 # endif 126 191 #endif 127 192 128 void WinMainStartup_OldWindowsHelper()193 void Startup_OldWindowsHelper() 129 194 { 130 195 __security_init_cookie(); 131 196 // MessageBox(0, "Startup", "", 0); 132 197 InitializeOldWindowsHelper(); 133 198 134 199 __asm 135 200 { 136 jmp tWinMainCRTStartup;201 jmp CRTStartup; 137 202 } 138 203 }
Note:
See TracChangeset
for help on using the changeset viewer.