Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp	(revision 800)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp	(revision 801)
@@ -590,6 +590,6 @@
 
 	// グローバルローケルを日本語にする
-	std::locale::global(std::locale("japanese"));
-	_setmode(_fileno(stdout), _O_BINARY);
+	//std::locale::global(std::locale("japanese"));
+	//_setmode(_fileno(stdout), _O_BINARY);
 
 	//_Test();
Index: /branches/egtra/ab5.0/abdev/OldWindowsHelper.asm
===================================================================
--- /branches/egtra/ab5.0/abdev/OldWindowsHelper.asm	(revision 800)
+++ /branches/egtra/ab5.0/abdev/OldWindowsHelper.asm	(revision 801)
@@ -20,4 +20,8 @@
 	ImportTrap InterlockedPopEntrySList, 4
 	ImportTrap InterlockedCompareExchange, 12
+	ImportTrap GetModuleHandleW, 4
+	ImportTrap GetStartupInfoW, 4
+	ImportTrap GetEnvironmentStringsW, 0
+	ImportTrap FreeEnvironmentStringsW, 4
 	TrapTableLast LABEL DWORD
 
Index: /branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp	(revision 800)
+++ /branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp	(revision 801)
@@ -1,4 +1,5 @@
 #include "stdafx.h"
 #include <cstdint>
+#include <cstring>
 #include <process.h>
 #include "OSVersion.h"
@@ -16,4 +17,8 @@
 	extern FARPROC alias__imp__InterlockedPushEntrySList;
 	extern FARPROC alias__imp__InterlockedPopEntrySList;
+	extern FARPROC alias__imp__GetModuleHandleW;
+	extern FARPROC alias__imp__GetStartupInfoW;
+	extern FARPROC alias__imp__GetEnvironmentStringsW;
+	extern FARPROC alias__imp__FreeEnvironmentStringsW;
 	extern void* TrapTableLast;
 } // extern "C"
@@ -26,5 +31,5 @@
 	if (hmodKernel == nullptr)
 	{
-		hmodKernel = GetModuleHandle(TEXT("kernel32"));
+		hmodKernel = GetModuleHandleA("kernel32");
 	}
 	return hmodKernel;
@@ -65,5 +70,5 @@
 #pragma warning(pop)
 
-__declspec(naked) long __stdcall Alternative_InterlockedCompareExchange(long volatile*, long, long)
+__declspec(naked) long WINAPI Alternative_InterlockedCompareExchange(long volatile*, long, long)
 {
 	__asm
@@ -83,4 +88,46 @@
 }
 
+HMODULE WINAPI Alternative_GetModuleHandleW(LPCWSTR moduleName)
+{
+	HMODULE ret = nullptr;
+	auto size = std::wcslen(moduleName) + 1;
+	auto mbsSize = size * 2;
+	if (auto buffer = static_cast<LPSTR>(::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, mbsSize)))
+	{
+		if (::WideCharToMultiByte(CP_ACP, 0, moduleName, static_cast<int>(size), buffer, static_cast<int>(mbsSize), nullptr, nullptr) > 0)
+		{
+			ret = ::GetModuleHandleA(buffer);
+		}
+		::HeapFree(::GetProcessHeap(), 0, buffer);
+	}
+	return ret;
+}
+
+// CRT用に最小限の実装
+void WINAPI Alternative_GetStartupInfoW(LPSTARTUPINFOW psi)
+{
+	STARTUPINFOA sia;
+	::GetStartupInfoA(&sia);
+
+	*psi = STARTUPINFOW();
+	psi->cb = sizeof *psi;
+	if (sia.dwFlags & STARTF_USESHOWWINDOW)
+	{
+		psi->dwFlags = STARTF_USESHOWWINDOW;
+		psi->wShowWindow = sia.wShowWindow;
+	}
+}
+
+LPWCH WINAPI Alternative_GetEnvironmentStringsW()
+{
+	static WCHAR c[2];
+	return c;
+}
+
+BOOL WINAPI Alternative_FreeEnvironmentStringsW(LPWCH)
+{
+	return TRUE;
+}
+
 #define FUNCTION_INIT(name) \
 	if (auto f = ::GetProcAddress(GetKernelModule(), #name)) { \
@@ -88,4 +135,11 @@
 	} else { \
 		alias__imp__ ## name = reinterpret_cast<FARPROC>(Alternative_ ## name); \
+	}
+
+#define FUNCTION_INIT_9X(name) \
+	if (ActiveBasic::Common::Is9x()) { \
+		alias__imp__ ## name = reinterpret_cast<FARPROC>(Alternative_ ## name); \
+	} else { \
+		alias__imp__ ## name = ::GetProcAddress(GetKernelModule(), #name); \
 	}
 
@@ -100,12 +154,13 @@
 	FUNCTION_INIT(DecodePointer);
 	FUNCTION_INIT(HeapSetInformation);
-	alias__imp__InitializeCriticalSectionAndSpinCount = 
-		ActiveBasic::Common::Is9x()
-		? reinterpret_cast<FARPROC>(Alternative_InitializeCriticalSectionAndSpinCount)
-		: ::GetProcAddress(GetKernelModule(), "InitializeCriticalSectionAndSpinCount");
+	FUNCTION_INIT_9X(InitializeCriticalSectionAndSpinCount);
 	FUNCTION_INIT(InterlockedCompareExchange);
 	FUNCTION_INIT(IsProcessorFeaturePresent);
 	alias__imp__InterlockedPushEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPushEntrySList");
 	alias__imp__InterlockedPopEntrySList = ::GetProcAddress(GetKernelModule(), "InterlockedPopEntrySList");
+	FUNCTION_INIT_9X(GetModuleHandleW);
+	FUNCTION_INIT_9X(GetStartupInfoW);
+	FUNCTION_INIT_9X(GetEnvironmentStringsW);
+	FUNCTION_INIT_9X(FreeEnvironmentStringsW);
 
 	::VirtualProtect(&TrapTableFirst,
@@ -118,21 +173,31 @@
 extern "C"
 {
-#ifdef _UNICODE
-int wWinMainCRTStartup();
-#define tWinMainCRTStartup wWinMainCRTStartup
+#ifdef _CONSOLE
+#	ifdef _UNICODE
+		int wmainCRTStartup();
+#		define CRTStartup wmainCRTStartup
+#	else
+		int mainCRTStartup();
+#		define CRTStartup mainCRTStartup
+#	endif
 #else
-int WinMainCRTStartup();
-#define tWinMainCRTStartup WinMainCRTStartup
+#	ifdef _UNICODE
+		int wWinMainCRTStartup();
+#		define CRTStartup wWinMainCRTStartup
+#	else
+		int WinMainCRTStartup();
+#		define CRTStartup WinMainCRTStartup
+#	endif
 #endif
 
-void WinMainStartup_OldWindowsHelper()
+void Startup_OldWindowsHelper()
 {
 	__security_init_cookie();
-
+//	MessageBox(0, "Startup", "", 0);
 	InitializeOldWindowsHelper();
 
 	__asm
 	{
-		jmp	tWinMainCRTStartup;
+		jmp	CRTStartup;
 	}
 }
Index: /branches/egtra/ab5.0/abdev/abdev/abdev.vcxproj
===================================================================
--- /branches/egtra/ab5.0/abdev/abdev/abdev.vcxproj	(revision 800)
+++ /branches/egtra/ab5.0/abdev/abdev/abdev.vcxproj	(revision 801)
@@ -115,5 +115,5 @@
       <SubSystem>Windows</SubSystem>
       <TargetMachine>MachineX86</TargetMachine>
-      <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
+      <EntryPointSymbol>Startup_OldWindowsHelper</EntryPointSymbol>
     </Link>
     <Manifest>
@@ -153,5 +153,6 @@
       <SubSystem>Windows</SubSystem>
       <TargetMachine>MachineX64</TargetMachine>
-      <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
+      <EntryPointSymbol>
+      </EntryPointSymbol>
     </Link>
     <Manifest>
@@ -194,5 +195,5 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <TargetMachine>MachineX86</TargetMachine>
-      <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
+      <EntryPointSymbol>Startup_OldWindowsHelper</EntryPointSymbol>
     </Link>
     <Manifest>
@@ -235,5 +236,6 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <TargetMachine>MachineX64</TargetMachine>
-      <EntryPointSymbol>WinMainStartup_OldWindowsHelper</EntryPointSymbol>
+      <EntryPointSymbol>
+      </EntryPointSymbol>
     </Link>
     <Manifest>
Index: /branches/egtra/ab5.0/abdev/compiler.vcxproj
===================================================================
--- /branches/egtra/ab5.0/abdev/compiler.vcxproj	(revision 800)
+++ /branches/egtra/ab5.0/abdev/compiler.vcxproj	(revision 801)
@@ -46,4 +46,5 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
+    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
   </ImportGroup>
   <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
@@ -98,5 +99,5 @@
       <Optimization>Disabled</Optimization>
       <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_DEBUG;_WINDOWS;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_DEBUG;_CONSOLE;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>false</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -116,4 +117,6 @@
       <SubSystem>Console</SubSystem>
       <StackReserveSize>4194304</StackReserveSize>
+      <EntryPointSymbol>mainStartup_OldWindowsHelper</EntryPointSymbol>
+      <DelayLoadDLLs>PSAPI.DLL</DelayLoadDLLs>
     </Link>
     <Manifest>
@@ -138,5 +141,5 @@
       <Optimization>Disabled</Optimization>
       <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_DEBUG;_WINDOWS;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_DEBUG;_CONSOLE;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>false</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -179,5 +182,5 @@
       <Optimization>MaxSpeed</Optimization>
       <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>NDEBUG;_WINDOWS;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>NDEBUG;_CONSOLE;JPN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
       <PrecompiledHeader>Use</PrecompiledHeader>
@@ -197,4 +200,6 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <ImageHasSafeExceptionHandlers>true</ImageHasSafeExceptionHandlers>
+      <EntryPointSymbol>Startup_OldWindowsHelper</EntryPointSymbol>
+      <DelayLoadDLLs>PSAPI.DLL</DelayLoadDLLs>
     </Link>
     <Manifest>
@@ -219,5 +224,5 @@
       <Optimization>MaxSpeed</Optimization>
       <AdditionalIncludeDirectories>..\;BasicCompiler_Common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>NDEBUG;_WINDOWS;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>NDEBUG;_CONSOLE;JPN;_AMD64_;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
       <PrecompiledHeader>Use</PrecompiledHeader>
@@ -839,4 +844,8 @@
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+    </ClCompile>
+    <ClCompile Include="OldWindowsHelperImpl.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
     </ClCompile>
   </ItemGroup>
@@ -918,6 +927,13 @@
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <MASM Include="OldWindowsHelper.asm">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+    </MASM>
+  </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
+    <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
   </ImportGroup>
 </Project>
Index: /branches/egtra/ab5.0/abdev/compiler.vcxproj.filters
===================================================================
--- /branches/egtra/ab5.0/abdev/compiler.vcxproj.filters	(revision 800)
+++ /branches/egtra/ab5.0/abdev/compiler.vcxproj.filters	(revision 801)
@@ -391,4 +391,7 @@
       <Filter>Source Files\x64Compiler\Procedure\Opcode</Filter>
     </ClCompile>
+    <ClCompile Include="OldWindowsHelperImpl.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
@@ -563,3 +566,8 @@
     </None>
   </ItemGroup>
+  <ItemGroup>
+    <MASM Include="OldWindowsHelper.asm">
+      <Filter>Source Files</Filter>
+    </MASM>
+  </ItemGroup>
 </Project>
