# HG changeset patch # User Frank Benoit # Date 1202765878 -3600 # Node ID e3b3f0fc0c7b44af26f0ce08e4c7ae5a17d35533 # Parent d7264281cb4ab0e90dd0dbae03ac99b6c79fdd80 Fix removing the temp file and use the conduit from tango.io.Tempfile. Thanks doob for investigating here. diff -r d7264281cb4a -r e3b3f0fc0c7b dwt/internal/win32/OS.d --- a/dwt/internal/win32/OS.d Mon Feb 11 04:33:36 2008 +0100 +++ b/dwt/internal/win32/OS.d Mon Feb 11 22:37:58 2008 +0100 @@ -30,6 +30,7 @@ import tango.util.log.Trace; +import tango.io.Console; void trace(int line ){ //Trace.formatln( "OS {}", line ); } @@ -240,7 +241,6 @@ //IsSP = IsSP(); //PORTING_CHANGE: made by version //IsPPC = IsPPC(); -trace(__LINE__); version(WinCE) { IsHPC = IsWinCE && !IsPPC && !IsSP; } @@ -248,7 +248,6 @@ WIN32_MINOR = info.dwMinorVersion; WIN32_VERSION = VERSION (WIN32_MAJOR, WIN32_MINOR); -trace(__LINE__); // when to load uxtheme if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { loadLib( Symbols_UxTheme, `UxTheme.dll` ); @@ -266,62 +265,51 @@ loadLib( Symbols_Kernel32, `Kernel32.dll` ); } -trace(__LINE__); //PORTING_CHANGE: made by version //IsUnicode = !IsWin32s && !IsWin95; + /* Load the manifest to force the XP Theme */ if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { - ULONG_PTR ulpActivationCookie; + const char[] manifest = ` + + + D Widget Toolkit + + + + + +`; + + scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent); + temp.write(manifest); + temp.detach(); + ACTCTX actctx; - HANDLE hActCtx = INVALID_HANDLE_VALUE; - DWORD dwLastError; - - tango.io.TempFile.TempFile.Style style = {tango.io.TempFile.TempFile.Transience.Transient}; - - scope File file; - scope temp = new tango.io.TempFile.TempFile(style); - scope filePath = temp.path; - - const char[] filename = "dwt.manifest"; - const char[] manifest = ` - - - D Widget Toolkit - - - - - - `; - - filePath.file = filename; - - if (!filePath.exists) - { - file = new File(filePath.toString); - file.write(manifest); - } - - memset(&actctx, 0, actctx.sizeof); actctx.cbSize = actctx.sizeof; - actctx.lpSource = toString16(filePath.toString).toString16z(); - - // Create the activation context, then delete the string - we don't need it - // anymore. - hActCtx = OS.CreateActCtx(&actctx); + actctx.lpSource = StrToTCHARz( 0, temp.toString ); + + // Create the activation context + HANDLE hActCtx = OS.CreateActCtx(&actctx); // Did we fail creating the activation context? - if (hActCtx == INVALID_HANDLE_VALUE) + if (hActCtx is INVALID_HANDLE_VALUE){ Trace.formatln("The Activation Context could not be created"); + goto LActCtxError; + } // Activate the context and make use of it - if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)) + ULONG_PTR ulpActivationCookie; + if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ Trace.formatln("The Activation Context failed to load"); - + goto LActCtxError; + } + + LActCtxError: + temp.path.remove(); /+ //if (System.getProperty (NO_MANIFEST) is null) { -trace(__LINE__); TCHAR[] buffer = new TCHAR[ MAX_PATH ]; HANDLE hModule = OS.GetLibraryHandle (); while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) { @@ -331,20 +319,15 @@ int byteCount = buffer.length * TCHAR.sizeof; TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory (pszText, buffer.ptr, byteCount); -trace(__LINE__); ACTCTX pActCtx; pActCtx.cbSize = ACTCTX.sizeof; pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT; pActCtx.lpSource = pszText; pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID; -trace(__LINE__); -//Trace.formatln( "is loaded {}", ( OS.CreateActCtx !is null )); HANDLE hActCtx = OS.CreateActCtx (&pActCtx); -trace(__LINE__); if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); uint lpCookie; OS.ActivateActCtx (hActCtx, &lpCookie); -trace(__LINE__); /* * NOTE: A single activation context is created and activated * for the entire lifetime of the program. It is deactivated @@ -360,7 +343,6 @@ BOOL dbcsEnabled = OS.GetSystemMetrics (SM_DBCSENABLED) !is 0; BOOL immEnabled = OS.GetSystemMetrics (SM_IMMENABLED) !is 0; IsDBLocale = dbcsEnabled || immEnabled; -trace(__LINE__); /* * Bug in Windows. On Korean Windows XP when the Text @@ -376,18 +358,15 @@ if (!OS.IsWinCE && OS.WIN32_VERSION is OS.VERSION (5, 1)) { short langID = OS.GetSystemDefaultUILanguage (); short primaryLang = OS.PRIMARYLANGID (langID); -trace(__LINE__); if (primaryLang is LANG_KOREAN) { OSVERSIONINFOEX infoex; infoex.dwOSVersionInfoSize = OSVERSIONINFOEX.sizeof; GetVersionEx (cast(OSVERSIONINFO*) &infoex ); if (infoex.wServicePackMajor < 2) { -trace(__LINE__); OS.ImmDisableTextFrameService (0); } } } -trace(__LINE__); /* Get the COMCTL32.DLL version */ DLLVERSIONINFO dvi; @@ -400,17 +379,13 @@ if (auto lib = SharedLib.load( `comctl32.dll`) ) { char[] name = "DllGetVersion\0"; //$NON-NLS-1$ void* DllGetVersion = lib.getSymbol(name.ptr); -trace(__LINE__); if (DllGetVersion !is null){ alias extern(Windows) void function(DLLVERSIONINFO*) TDllVersion; TDllVersion f = cast( TDllVersion )DllGetVersion; -trace(__LINE__); f(&dvi); } -trace(__LINE__); lib.unload(); } -trace(__LINE__); COMCTL32_MAJOR = dvi.dwMajorVersion; COMCTL32_MINOR = dvi.dwMinorVersion; COMCTL32_VERSION = VERSION (COMCTL32_MAJOR, COMCTL32_MINOR); @@ -421,24 +396,19 @@ dvi.dwMajorVersion = 4; //TCHAR lpLibFileName = new TCHAR (0, "Shell32.dll", true); //$NON-NLS-1$ //int /*long*/ hModule = OS.LoadLibrary (lpLibFileName); -trace(__LINE__); if ( auto lib = SharedLib.load( `Shell32.dll`)) { char[] name = "DllGetVersion\0"; //$NON-NLS-1$ void* DllGetVersion = lib.getSymbol(name.ptr); -trace(__LINE__); if (DllGetVersion !is null){ alias extern(Windows) void function(DLLVERSIONINFO*) TDllVersion; TDllVersion f = cast( TDllVersion )DllGetVersion; -trace(__LINE__); f(&dvi); } -trace(__LINE__); lib.unload(); } SHELL32_MAJOR = dvi.dwMajorVersion; SHELL32_MINOR = dvi.dwMinorVersion; SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR); -trace(__LINE__); } /* Flag used on WinCE */