Ignore:
Timestamp:
Feb 6, 2011, 9:47:29 PM (13 years ago)
Author:
イグトランス (egtra)
Message:

コンパイラにXP以前対応用のコードを適用

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp

    r800 r801  
    11#include "stdafx.h"
    22#include <cstdint>
     3#include <cstring>
    34#include <process.h>
    45#include "OSVersion.h"
     
    1617    extern FARPROC alias__imp__InterlockedPushEntrySList;
    1718    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;
    1823    extern void* TrapTableLast;
    1924} // extern "C"
     
    2631    if (hmodKernel == nullptr)
    2732    {
    28         hmodKernel = GetModuleHandle(TEXT("kernel32"));
     33        hmodKernel = GetModuleHandleA("kernel32");
    2934    }
    3035    return hmodKernel;
     
    6570#pragma warning(pop)
    6671
    67 __declspec(naked) long __stdcall Alternative_InterlockedCompareExchange(long volatile*, long, long)
     72__declspec(naked) long WINAPI Alternative_InterlockedCompareExchange(long volatile*, long, long)
    6873{
    6974    __asm
     
    8388}
    8489
     90HMODULE 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用に最小限の実装
     107void 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
     121LPWCH WINAPI Alternative_GetEnvironmentStringsW()
     122{
     123    static WCHAR c[2];
     124    return c;
     125}
     126
     127BOOL WINAPI Alternative_FreeEnvironmentStringsW(LPWCH)
     128{
     129    return TRUE;
     130}
     131
    85132#define FUNCTION_INIT(name) \
    86133    if (auto f = ::GetProcAddress(GetKernelModule(), #name)) { \
     
    88135    } else { \
    89136        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); \
    90144    }
    91145
     
    100154    FUNCTION_INIT(DecodePointer);
    101155    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);
    106157    FUNCTION_INIT(InterlockedCompareExchange);
    107158    FUNCTION_INIT(IsProcessorFeaturePresent);
    108159    alias__imp__InterlockedPushEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPushEntrySList");
    109160    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);
    110165
    111166    ::VirtualProtect(&TrapTableFirst,
     
    118173extern "C"
    119174{
    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
    123183#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
    126191#endif
    127192
    128 void WinMainStartup_OldWindowsHelper()
     193void Startup_OldWindowsHelper()
    129194{
    130195    __security_init_cookie();
    131 
     196//  MessageBox(0, "Startup", "", 0);
    132197    InitializeOldWindowsHelper();
    133198
    134199    __asm
    135200    {
    136         jmp tWinMainCRTStartup;
     201        jmp CRTStartup;
    137202    }
    138203}
Note: See TracChangeset for help on using the changeset viewer.