Changeset 785 in dev for branches/egtra/ab5.0/abdev
- Timestamp:
- Jan 30, 2011, 12:08:38 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp
r784 r785 1 1 #include "stdafx.h" 2 2 3 static OSVERSIONINFO GetVersionEx2() 3 #define GET_PROC_ADDRESS(hmod, functionName) reinterpret_cast<decltype(functionName)*>(GetProcAddress((hmod), #functionName)) 4 5 namespace 6 { 7 8 OSVERSIONINFO GetVersionEx2() 4 9 { 5 10 OSVERSIONINFO vi = {sizeof vi}; … … 10 15 static OSVERSIONINFO const vi = GetVersionEx2(); 11 16 12 #define KERNEL32 (GetModuleHandle(TEXT("kernel32"))) 17 HMODULE GetKernelModule() 18 { 19 static HMODULE hmod = GetModuleHandle(TEXT("kernel32")); 20 return hmod; 21 } 13 22 14 #define GET_PROC_ADDRESS(hmod, functionName) reinterpret_cast<decltype(functionName)*>(GetProcAddress((hmod), #functionName)) 23 } 15 24 16 25 extern "C" … … 18 27 BOOL WINAPI IsDebuggerPresent_Helper() 19 28 { 20 if (auto IsDebuggerPresent_Real = GET_PROC_ADDRESS(KERNEL32, IsDebuggerPresent)) 29 static auto IsDebuggerPresent_Real = GET_PROC_ADDRESS(GetKernelModule(), IsDebuggerPresent); 30 if (IsDebuggerPresent_Real) 21 31 { 22 32 return IsDebuggerPresent_Real(); … … 30 40 void* WINAPI EncodePointer_Helper(void* p) 31 41 { 32 if (auto EncodePointer_Real = GET_PROC_ADDRESS(KERNEL32, EncodePointer)) 42 static auto EncodePointer_Real = GET_PROC_ADDRESS(GetKernelModule(), EncodePointer); 43 if (EncodePointer_Real) 33 44 { 34 45 return EncodePointer_Real(p); … … 42 53 void* WINAPI DecodePointer_Helper(void* p) 43 54 { 44 if (auto DecodePointer_Real = GET_PROC_ADDRESS(KERNEL32, DecodePointer)) 55 static auto DecodePointer_Real = GET_PROC_ADDRESS(GetKernelModule(), DecodePointer); 56 if (DecodePointer_Real) 45 57 { 46 58 return DecodePointer_Real(p); … … 54 66 BOOL WINAPI IsProcessorFeaturePresent_Helper(DWORD feture) 55 67 { 56 if (auto IsProcessorFeaturePresent_Real = GET_PROC_ADDRESS(KERNEL32, IsProcessorFeaturePresent)) 68 static auto IsProcessorFeaturePresent_Real = GET_PROC_ADDRESS(GetKernelModule(), IsProcessorFeaturePresent); 69 if (IsProcessorFeaturePresent_Real) 57 70 { 58 71 return IsProcessorFeaturePresent_Real(feture); … … 67 80 BOOL WINAPI HeapSetInformation_Helper(HANDLE hHeap, HEAP_INFORMATION_CLASS hic, void* information, SSIZE_T informationLength) 68 81 { 69 if (auto HeapSetInformation_Real = GET_PROC_ADDRESS(KERNEL32, HeapSetInformation)) 82 static auto HeapSetInformation_Real = GET_PROC_ADDRESS(GetKernelModule(), HeapSetInformation); 83 if (HeapSetInformation_Real) 70 84 { 71 85 return HeapSetInformation_Real(hHeap, hic, information, informationLength); … … 77 91 } 78 92 93 namespace 94 { 95 typedef decltype(InitializeCriticalSectionAndSpinCount)* PInitializeCriticalSectionAndSpinCount; 96 97 // 関数内静的変数とSEHは両立できないようなので別の関数へ分離 98 BOOL WINAPI InitializeCriticalSectionAndSpinCount_Helper2(PInitializeCriticalSectionAndSpinCount pfn, LPCRITICAL_SECTION lpcs, DWORD spinCount) 99 { 100 __try 101 { 102 if (pfn != nullptr) 103 { 104 BOOL ret = pfn(lpcs, spinCount); 105 return vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS 106 ? TRUE 107 : ret; 108 } 109 else 110 { 111 ::InitializeCriticalSection(lpcs); 112 return TRUE; 113 } 114 } 115 __except(EXCEPTION_EXECUTE_HANDLER) 116 { 117 } 118 ::SetLastError(ERROR_OUTOFMEMORY); 119 return FALSE; 120 } 121 } 122 79 123 BOOL WINAPI InitializeCriticalSectionAndSpinCount_Helper(LPCRITICAL_SECTION lpcs, DWORD spinCount) 80 124 { 81 __try 82 { 83 if (auto InitializeCriticalSectionAndSpinCount_Real = GET_PROC_ADDRESS(KERNEL32, InitializeCriticalSectionAndSpinCount)) 84 { 85 OSVERSIONINFO vi = {sizeof vi}; 86 ::GetVersionEx(&vi); 87 BOOL ret = InitializeCriticalSectionAndSpinCount_Real(lpcs, spinCount); 88 return vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS 89 ? TRUE 90 : ret; 91 } 92 else 93 { 94 ::InitializeCriticalSection(lpcs); 95 return TRUE; 96 } 97 } 98 __except(EXCEPTION_EXECUTE_HANDLER) 99 { 100 } 101 return FALSE; 125 static auto InitializeCriticalSectionAndSpinCount_Real = GET_PROC_ADDRESS(GetKernelModule(), InitializeCriticalSectionAndSpinCount); 126 return InitializeCriticalSectionAndSpinCount_Helper2(InitializeCriticalSectionAndSpinCount_Real, lpcs, spinCount); 102 127 } 103 128 … … 109 134 PSLIST_ENTRY WINAPI InterlockedPushEntrySList_Helper(PSLIST_HEADER head, PSLIST_ENTRY entry) 110 135 { 111 auto InterlockedPushEntrySList_Real = GET_PROC_ADDRESS(KERNEL32, InterlockedPushEntrySList);136 static auto InterlockedPushEntrySList_Real = GET_PROC_ADDRESS(GetKernelModule(), InterlockedPushEntrySList); 112 137 assert(InterlockedPushEntrySList_Real != nullptr); 113 138 return InterlockedPushEntrySList_Real(head, entry); … … 116 141 PSLIST_ENTRY WINAPI InterlockedPopEntrySList_Helper(PSLIST_HEADER head) 117 142 { 118 auto InterlockedPopEntrySList_Real = GET_PROC_ADDRESS(KERNEL32, InterlockedPopEntrySList);143 static auto InterlockedPopEntrySList_Real = GET_PROC_ADDRESS(GetKernelModule(), InterlockedPopEntrySList); 119 144 assert(InterlockedPopEntrySList_Real != nullptr); 120 145 return InterlockedPopEntrySList_Real(head);
Note:
See TracChangeset
for help on using the changeset viewer.