Turn WinLauncher into a stub .exe launcher and a .dll that contains all the real...
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2012 14:52:23 +0000 (14:52 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jan 2012 14:52:23 +0000 (14:52 +0000)
This allows us to add the Apple Application Support directory to PATH before trying to load
WebKit so that CoreGraphics.dll and friends can be found. Eventually all our WebKit apps
should use this mechanism.

Fixes <http://webkit.org/b/68578> <rdar://problem/10163861> WinLauncher fails to launch when
double-clicked

Reviewed by Anders Carlsson.

Tools:

* WinLauncher/WinLauncher.cpp: Removed InitInstance.
(DllMain): Added. Stores the DLL HINSTANCE in the global hInst variable. This used to be
done by the now-removed InitInstance function.
(dllLauncherEntryPoint): Renamed from _tWinMain. This is the function that our stub launcher
calls. Merged code from InitInstance into this function, and change to use the global hInst
variable, which corresponds to WinLauncher.dll, rather than the HINSTANCE passed into this
function, which corresponds to WinLauncher.exe.

* WinLauncher/WinLauncher.vcproj:
* WinLauncher/WinLauncherCommon.vsprops:
Changed to build WinLauncher.dll instead of WinLauncher.exe.

* WinLauncher/WinLauncherLauncher.rc: Added.
* WinLauncher/WinLauncherLauncherResource.h: Added.
This just references the WinLauncher.ico file to set the application icon (though it looks
like that's a default icon).

* WinLauncher/WinLauncherLauncher.vcproj: Copied from Tools/WinLauncher/WinLauncher.vcproj
but changed to build WinLauncher.exe using the new DLLLauncherMain.cpp file.

* WinLauncher/WinLauncherLauncherCommon.vsprops: Added.
* WinLauncher/WinLauncherLauncherDebug.vsprops: Added.
* WinLauncher/WinLauncherLauncherDebugAll.vsprops: Added.
* WinLauncher/WinLauncherLauncherDebugCairoCFLite.vsprops: Added.
* WinLauncher/WinLauncherLauncherProduction.vsprops: Added.
* WinLauncher/WinLauncherLauncherRelease.vsprops: Added.
* WinLauncher/WinLauncherLauncherReleaseCairoCFLite.vsprops: Added.

* win/DLLLauncher/DLLLauncherMain.cpp: Added.
(enableTerminationOnHeapCorruption): Uses HeapSetInformation to tell Windows to kill the
program if it detects heap corruption.
(getStringValue): Helper function to read a string value from the registry.
(applePathFromRegistry): Helper function to read the InstallDir for a given Apple
application from the registry.
(appleApplicationSupportDirectory): Helper function to return the path to the Apple
Application Support directory.
(copyEnvironmentVariable): Helper function to copy an environment variable's value.
(prependPath): Helper function to prepend a directory to the PATH.
(fatalError): Helper function to display an error to the user.
(wWinMain): Add Apple Application Support to the PATH, then load our DLL and call its
dllLauncherEntryPoint function.

Source/WebKit/win:

Add WinLauncherLauncher to WebKit.sln

It builds just after WinLauncher.

* WebKit.vcproj/WebKit.sln: Added WinLauncherLauncher.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@104153 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebKit.vcproj/WebKit.sln
Tools/ChangeLog
Tools/WinLauncher/WinLauncher.cpp
Tools/WinLauncher/WinLauncher.vcproj
Tools/WinLauncher/WinLauncherCommon.vsprops
Tools/WinLauncher/WinLauncherLauncher.rc [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncher.vcproj [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherCommon.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherDebug.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherDebugAll.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherDebugCairoCFLite.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherProduction.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherRelease.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherReleaseCairoCFLite.vsprops [new file with mode: 0644]
Tools/WinLauncher/WinLauncherLauncherResource.h [new file with mode: 0644]
Tools/win/DLLLauncher/DLLLauncherMain.cpp [new file with mode: 0644]

index 16f5c14..5470e32 100644 (file)
@@ -1,3 +1,16 @@
+2012-01-04  Adam Roben  <aroben@apple.com>
+
+        Add WinLauncherLauncher to WebKit.sln
+
+        It builds just after WinLauncher.
+
+        Part of <http://webkit.org/b/68578> <rdar://problem/10163861> WinLauncher fails to launch
+        when double-clicked
+
+        Reviewed by Anders Carlsson.
+
+        * WebKit.vcproj/WebKit.sln: Added WinLauncherLauncher.
+
 2011-12-21  Jessie Berlin  <jberlin@apple.com>
 
         Expose to Windows the way to allow a scheme access to Local Storage and Databases while
index 62cd699..f221ebe 100644 (file)
@@ -95,7 +95,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "record-memory-win", "..\..\
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestNetscapePlugin", "..\..\..\..\Tools\DumpRenderTree\TestNetscapePlugIn\win\TestNetscapePlugin.vcproj", "{C0737398-3565-439E-A2B8-AB2BE4D5430C}"
        ProjectSection(ProjectDependencies) = postProject
-               {114FCA11-216B-4C8C-957E-30A75AE80443} = {114FCA11-216B-4C8C-957E-30A75AE80443}
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4} = {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebKitLauncherWin", "..\..\..\..\Tools\WebKitLauncherWin\WebKitLauncherWin.vcproj", "{D09806DB-E58B-4646-8C9B-61101906C1E2}"
@@ -158,6 +158,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testRegExp", "..\..\..\Java
                {C59E5129-B453-49B7-A52B-1E104715F76E} = {C59E5129-B453-49B7-A52B-1E104715F76E}
        EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinLauncherLauncher", "..\..\..\..\Tools\WinLauncher\WinLauncherLauncher.vcproj", "{767B10FB-76C1-44D0-8005-85ED7F9AA5E4}"
+       ProjectSection(ProjectDependencies) = postProject
+               {114FCA11-216B-4C8C-957E-30A75AE80443} = {114FCA11-216B-4C8C-957E-30A75AE80443}
+       EndProjectSection
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug_All|Win32 = Debug_All|Win32
@@ -526,6 +531,18 @@ Global
                {14C94979-1ED3-4E1D-9B55-A80FCF4677D0}.Release_Cairo_CFLite|Win32.Build.0 = Release_Cairo_CFLite|Win32
                {14C94979-1ED3-4E1D-9B55-A80FCF4677D0}.Release|Win32.ActiveCfg = Release|Win32
                {14C94979-1ED3-4E1D-9B55-A80FCF4677D0}.Release|Win32.Build.0 = Release|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Debug_All|Win32.ActiveCfg = Debug_All|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Debug_All|Win32.Build.0 = Debug_All|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Debug_Cairo_CFLite|Win32.ActiveCfg = Debug_Cairo_CFLite|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Debug_Cairo_CFLite|Win32.Build.0 = Debug_Cairo_CFLite|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Debug|Win32.ActiveCfg = Debug|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Debug|Win32.Build.0 = Debug|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Production|Win32.ActiveCfg = Production|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Production|Win32.Build.0 = Production|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Release_Cairo_CFLite|Win32.ActiveCfg = Release_Cairo_CFLite|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Release_Cairo_CFLite|Win32.Build.0 = Release_Cairo_CFLite|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Release|Win32.ActiveCfg = Release|Win32
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4}.Release|Win32.Build.0 = Release|Win32
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -561,5 +578,6 @@ Global
                {45C45411-7F0E-404D-919A-4EE9BB60BE86} = {62DCDFE4-EAD2-48E1-A2BD-BD54AD3C7459}
                {B0101604-B483-4F8C-9C51-90B46A2B1CD3} = {62DCDFE4-EAD2-48E1-A2BD-BD54AD3C7459}
                {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8} = {62DCDFE4-EAD2-48E1-A2BD-BD54AD3C7459}
+               {767B10FB-76C1-44D0-8005-85ED7F9AA5E4} = {62DCDFE4-EAD2-48E1-A2BD-BD54AD3C7459}
        EndGlobalSection
 EndGlobal
index 6d3c018..eefc4d6 100644 (file)
@@ -1,3 +1,58 @@
+2012-01-04  Adam Roben  <aroben@apple.com>
+
+        Turn WinLauncher into a stub .exe launcher and a .dll that contains all the real code
+
+        This allows us to add the Apple Application Support directory to PATH before trying to load
+        WebKit so that CoreGraphics.dll and friends can be found. Eventually all our WebKit apps
+        should use this mechanism.
+
+        Fixes <http://webkit.org/b/68578> <rdar://problem/10163861> WinLauncher fails to launch when
+        double-clicked
+
+        Reviewed by Anders Carlsson.
+
+        * WinLauncher/WinLauncher.cpp: Removed InitInstance.
+        (DllMain): Added. Stores the DLL HINSTANCE in the global hInst variable. This used to be
+        done by the now-removed InitInstance function.
+        (dllLauncherEntryPoint): Renamed from _tWinMain. This is the function that our stub launcher
+        calls. Merged code from InitInstance into this function, and change to use the global hInst
+        variable, which corresponds to WinLauncher.dll, rather than the HINSTANCE passed into this
+        function, which corresponds to WinLauncher.exe.
+
+        * WinLauncher/WinLauncher.vcproj:
+        * WinLauncher/WinLauncherCommon.vsprops:
+        Changed to build WinLauncher.dll instead of WinLauncher.exe.
+
+        * WinLauncher/WinLauncherLauncher.rc: Added.
+        * WinLauncher/WinLauncherLauncherResource.h: Added.
+        This just references the WinLauncher.ico file to set the application icon (though it looks
+        like that's a default icon).
+
+        * WinLauncher/WinLauncherLauncher.vcproj: Copied from Tools/WinLauncher/WinLauncher.vcproj
+        but changed to build WinLauncher.exe using the new DLLLauncherMain.cpp file.
+
+        * WinLauncher/WinLauncherLauncherCommon.vsprops: Added.
+        * WinLauncher/WinLauncherLauncherDebug.vsprops: Added.
+        * WinLauncher/WinLauncherLauncherDebugAll.vsprops: Added.
+        * WinLauncher/WinLauncherLauncherDebugCairoCFLite.vsprops: Added.
+        * WinLauncher/WinLauncherLauncherProduction.vsprops: Added.
+        * WinLauncher/WinLauncherLauncherRelease.vsprops: Added.
+        * WinLauncher/WinLauncherLauncherReleaseCairoCFLite.vsprops: Added.
+
+        * win/DLLLauncher/DLLLauncherMain.cpp: Added.
+        (enableTerminationOnHeapCorruption): Uses HeapSetInformation to tell Windows to kill the
+        program if it detects heap corruption.
+        (getStringValue): Helper function to read a string value from the registry.
+        (applePathFromRegistry): Helper function to read the InstallDir for a given Apple
+        application from the registry.
+        (appleApplicationSupportDirectory): Helper function to return the path to the Apple
+        Application Support directory.
+        (copyEnvironmentVariable): Helper function to copy an environment variable's value.
+        (prependPath): Helper function to prepend a directory to the PATH.
+        (fatalError): Helper function to display an error to the user.
+        (wWinMain): Add Apple Application Support to the PATH, then load our DLL and call its
+        dllLauncherEntryPoint function.
+
 2012-01-05  Kentaro Hara  <haraken@chromium.org>
 
         prepare-ChangeLog cannot parse python code that nests classes and defs
index d9f46bd..4240925 100644 (file)
@@ -65,7 +65,6 @@ bool s_fullDesktop = false;
 
 // Forward declarations of functions included in this code module:
 ATOM                MyRegisterClass(HINSTANCE hInstance);
-BOOL                InitInstance(HINSTANCE, int);
 LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
 INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
 LRESULT CALLBACK    MyEditProc(HWND, UINT, WPARAM, LPARAM);
@@ -231,19 +230,21 @@ static void computeFullDesktopFrame()
     s_windowSize.cy = desktop.bottom - desktop.top;
 }
 
-int APIENTRY _tWinMain(HINSTANCE hInstance,
-                     HINSTANCE hPrevInstance,
-                     LPTSTR    lpCmdLine,
-                     int       nCmdShow)
+BOOL WINAPI DllMain(HINSTANCE dllInstance, DWORD reason, LPVOID)
+{
+    if (reason == DLL_PROCESS_ATTACH)
+        hInst = dllInstance;
+
+    return TRUE;
+}
+
+extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE, HINSTANCE, LPTSTR, int nCmdShow)
 {
 #ifdef _CRTDBG_MAP_ALLOC
     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
 #endif
 
-    UNREFERENCED_PARAMETER(hPrevInstance);
-    UNREFERENCED_PARAMETER(lpCmdLine);
-
      // TODO: Place code here.
     MSG msg = {0};
     HACCEL hAccelTable;
@@ -264,17 +265,13 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
     }
 
     // Initialize global strings
-    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
-    LoadString(hInstance, IDC_WINLAUNCHER, szWindowClass, MAX_LOADSTRING);
-    MyRegisterClass(hInstance);
+    LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
+    LoadString(hInst, IDC_WINLAUNCHER, szWindowClass, MAX_LOADSTRING);
+    MyRegisterClass(hInst);
 
     if (shouldUseFullDesktop())
         computeFullDesktopFrame();
 
-    // Perform application initialization:
-    if (!InitInstance (hInstance, nCmdShow))
-        return FALSE;
-
     // Init COM
     OleInitialize(NULL);
 
@@ -284,14 +281,23 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
                     s_windowPosition.x, s_windowPosition.y + s_windowSize.cy, s_windowSize.cx, URLBAR_HEIGHT,
                     0,
                     0,
-                    hInstance, 0);
+                    hInst, 0);
     } else {
+        hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
+                       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInst, 0);
+
+        if (!hMainWnd)
+            return FALSE;
+
         hURLBarWnd = CreateWindow(L"EDIT", 0,
                     WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 
                     0, 0, 0, 0,
                     hMainWnd,
                     0,
-                    hInstance, 0);
+                    hInst, 0);
+
+        ShowWindow(hMainWnd, nCmdShow);
+        UpdateWindow(hMainWnd);
     }
 
     DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWL_WNDPROC));
@@ -367,7 +373,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
     ShowWindow(gViewWindow, nCmdShow);
     UpdateWindow(gViewWindow);
 
-    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINLAUNCHER));
+    hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_WINLAUNCHER));
 
     // Main message loop:
     while (GetMessage(&msg, NULL, 0, 0)) {
@@ -418,25 +424,6 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
     return RegisterClassEx(&wcex);
 }
 
-BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
-{
-    hInst = hInstance; // Store instance handle in our global variable
-
-    if (usesLayeredWebView())
-        return TRUE;
-
-    hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
-                   CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
-
-    if (!hMainWnd)
-        return FALSE;
-
-    ShowWindow(hMainWnd, nCmdShow);
-    UpdateWindow(hMainWnd);
-
-    return TRUE;
-}
-
 static BOOL CALLBACK AbortProc(HDC hDC, int Error)
 {
     MSG msg;
index af95966..09ada0d 100644 (file)
@@ -17,7 +17,7 @@
        <Configurations>
                <Configuration
                        Name="Debug|Win32"
-                       ConfigurationType="1"
+                       ConfigurationType="2"
                        InheritedPropertySheets=".\WinLauncherDebug.vsprops"
                        CharacterSet="1"
                        >
@@ -78,7 +78,7 @@
                </Configuration>
                <Configuration
                        Name="Release|Win32"
-                       ConfigurationType="1"
+                       ConfigurationType="2"
                        InheritedPropertySheets=".\WinLauncherRelease.vsprops"
                        CharacterSet="1"
                        >
                </Configuration>
                <Configuration
                        Name="Debug_Cairo_CFLite|Win32"
-                       ConfigurationType="1"
+                       ConfigurationType="2"
                        InheritedPropertySheets=".\WinLauncherDebugCairoCFLite.vsprops"
                        CharacterSet="1"
                        >
                </Configuration>
                <Configuration
                        Name="Debug_All|Win32"
-                       ConfigurationType="1"
+                       ConfigurationType="2"
                        InheritedPropertySheets=".\WinLauncherDebugAll.vsprops"
                        CharacterSet="1"
                        >
                </Configuration>
                <Configuration
                        Name="Production|Win32"
-                       ConfigurationType="1"
+                       ConfigurationType="2"
                        InheritedPropertySheets=".\WinLauncherProduction.vsprops"
                        CharacterSet="1"
                        WholeProgramOptimization="1"
                </Configuration>
                <Configuration
                        Name="Release_Cairo_CFLite|Win32"
-                       ConfigurationType="1"
+                       ConfigurationType="2"
                        InheritedPropertySheets=".\WinLauncherReleaseCairoCFLite.vsprops"
                        CharacterSet="1"
                        >
index 9ca0797..7716c39 100644 (file)
@@ -12,5 +12,6 @@
        <Tool
                Name="VCLinkerTool"
                AdditionalDependencies="comdlg32.lib gdi32.lib comctl32.lib shlwapi.lib user32.lib ole32.lib oleaut32.lib WebKitGUID$(WebKitConfigSuffix).lib WebKit$(WebKitDLLConfigSuffix).lib"
+               OutputFile="$(OutDir)\$(ProjectName)$(WebKitConfigSuffix).dll"
        />
 </VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncher.rc b/Tools/WinLauncher/WinLauncherLauncher.rc
new file mode 100644 (file)
index 0000000..4079a2b
--- /dev/null
@@ -0,0 +1,76 @@
+// Microsoft Visual C++ generated resource script.\r
+//\r
+#include "WinLauncherLauncherResource.h"\r
+\r
+#define APSTUDIO_READONLY_SYMBOLS\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Generated from the TEXTINCLUDE 2 resource.\r
+//\r
+#define APSTUDIO_HIDDEN_SYMBOLS\r
+#include "windows.h"\r
+#undef APSTUDIO_HIDDEN_SYMBOLS\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+#undef APSTUDIO_READONLY_SYMBOLS\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+// English (U.S.) resources\r
+\r
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r
+#ifdef _WIN32\r
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US\r
+#pragma code_page(1252)\r
+#endif //_WIN32\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Icon\r
+//\r
+\r
+// Icon with lowest ID value placed first to ensure application icon\r
+// remains consistent on all systems.\r
+IDI_WINLAUNCHER         ICON                    "WinLauncher.ico"\r
+\r
+#ifdef APSTUDIO_INVOKED\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// TEXTINCLUDE\r
+//\r
+\r
+1 TEXTINCLUDE \r
+BEGIN\r
+    "WinLauncherLauncherResource.\0"\r
+END\r
+\r
+2 TEXTINCLUDE \r
+BEGIN\r
+    "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"\r
+    "#include ""windows.h""\r\n"\r
+    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"\r
+    "\0"\r
+END\r
+\r
+3 TEXTINCLUDE \r
+BEGIN\r
+    "\r\n"\r
+    "\0"\r
+END\r
+\r
+#endif    // APSTUDIO_INVOKED\r
+\r
+#endif    // English (U.S.) resources\r
+/////////////////////////////////////////////////////////////////////////////\r
+\r
+\r
+\r
+#ifndef APSTUDIO_INVOKED\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Generated from the TEXTINCLUDE 3 resource.\r
+//\r
+\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+#endif    // not APSTUDIO_INVOKED\r
+\r
diff --git a/Tools/WinLauncher/WinLauncherLauncher.vcproj b/Tools/WinLauncher/WinLauncherLauncher.vcproj
new file mode 100644 (file)
index 0000000..ec82a12
--- /dev/null
@@ -0,0 +1,420 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncher"
+       ProjectGUID="{767B10FB-76C1-44D0-8005-85ED7F9AA5E4}"
+       RootNamespace="WinLauncherLauncher"
+       Keyword="Win32Proj"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       ConfigurationType="1"
+                       InheritedPropertySheets=".\WinLauncherLauncherDebug.vsprops"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       ConfigurationType="1"
+                       InheritedPropertySheets=".\WinLauncherLauncherRelease.vsprops"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Debug_Cairo_CFLite|Win32"
+                       ConfigurationType="1"
+                       InheritedPropertySheets=".\WinLauncherLauncherDebugCairoCFLite.vsprops"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Debug_All|Win32"
+                       ConfigurationType="1"
+                       InheritedPropertySheets=".\WinLauncherLauncherDebugAll.vsprops"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Production|Win32"
+                       ConfigurationType="1"
+                       InheritedPropertySheets=".\WinLauncherLauncherProduction.vsprops"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release_Cairo_CFLite|Win32"
+                       ConfigurationType="1"
+                       InheritedPropertySheets=".\WinLauncherLauncherReleaseCairoCFLite.vsprops"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath="..\win\DLLLauncher\DLLLauncherMain.cpp"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+                       <File
+                               RelativePath=".\WinLauncher.ico"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\WinLauncherLauncher.rc"
+                               >
+                       </File>
+               </Filter>
+               <File
+                       RelativePath=".\WinLauncherLauncherResource.h"
+                       >
+               </File>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/Tools/WinLauncher/WinLauncherLauncherCommon.vsprops b/Tools/WinLauncher/WinLauncherLauncherCommon.vsprops
new file mode 100644 (file)
index 0000000..a29a518
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncherCommon"
+       >
+       <Tool
+               Name="VCLinkerTool"
+               AdditionalDependencies="shlwapi.lib"
+               OutputFile="$(OutDir)\WinLauncher$(WebKitConfigSuffix).exe"
+               ProgramDatabaseFile="$(TargetDir)$(TargetName)Launcher.pdb"
+       />
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherDebug.vsprops b/Tools/WinLauncher/WinLauncherLauncherDebug.vsprops
new file mode 100644 (file)
index 0000000..fb56bf2
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncherDebug"
+       InheritedPropertySheets="$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\common.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\debug.vsprops;.\WinLauncherLauncherCommon.vsprops"
+       >
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherDebugAll.vsprops b/Tools/WinLauncher/WinLauncherLauncherDebugAll.vsprops
new file mode 100644 (file)
index 0000000..d6b26eb
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncherDebugAll"
+       InheritedPropertySheets="$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\common.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\debug.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\debug_all.vsprops;.\WinLauncherLauncherCommon.vsprops"
+       >
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherDebugCairoCFLite.vsprops b/Tools/WinLauncher/WinLauncherLauncherDebugCairoCFLite.vsprops
new file mode 100644 (file)
index 0000000..48ad2c0
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherDebugCairoCFLite"
+       InheritedPropertySheets="$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\common.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\debug.vsprops"
+       >
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherProduction.vsprops b/Tools/WinLauncher/WinLauncherLauncherProduction.vsprops
new file mode 100644 (file)
index 0000000..fc8908b
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncherProduction"
+       InheritedPropertySheets="$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\common.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\releaseproduction.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\production.vsprops;.\WinLauncherLauncherCommon.vsprops"
+       >
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherRelease.vsprops b/Tools/WinLauncher/WinLauncherLauncherRelease.vsprops
new file mode 100644 (file)
index 0000000..aae42e3
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncherRelease"
+       InheritedPropertySheets="$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\common.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\releaseproduction.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\release.vsprops;.\WinLauncherLauncherCommon.vsprops"
+       >
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherReleaseCairoCFLite.vsprops b/Tools/WinLauncher/WinLauncherLauncherReleaseCairoCFLite.vsprops
new file mode 100644 (file)
index 0000000..9384136
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+       ProjectType="Visual C++"
+       Version="8.00"
+       Name="WinLauncherLauncherReleaseCairoCFLite"
+       InheritedPropertySheets="$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\common.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\releaseproduction.vsprops;$(WebKitVSPropsRedirectionDir)..\..\WebKitLibraries\win\tools\vsprops\release.vsprops;.\WinLauncherLauncherCommon.vsprops"
+       >
+</VisualStudioPropertySheet>
diff --git a/Tools/WinLauncher/WinLauncherLauncherResource.h b/Tools/WinLauncher/WinLauncherLauncherResource.h
new file mode 100644 (file)
index 0000000..961fb17
--- /dev/null
@@ -0,0 +1,20 @@
+//{{NO_DEPENDENCIES}}\r
+// Microsoft Visual C++ generated include file.\r
+// Used by WinLauncherLauncher.rc\r
+//\r
+#define IDD_WINLAUNCHER_DIALOG          102\r
+#define IDI_WINLAUNCHER                 107\r
+#define IDR_MAINFRAME                   128\r
+#define IDC_STATIC                      -1\r
+\r
+// Next default values for new objects\r
+// \r
+#ifdef APSTUDIO_INVOKED\r
+#ifndef APSTUDIO_READONLY_SYMBOLS\r
+#define _APS_NO_MFC                     1\r
+#define _APS_NEXT_RESOURCE_VALUE        129\r
+#define _APS_NEXT_COMMAND_VALUE         32771\r
+#define _APS_NEXT_CONTROL_VALUE         1000\r
+#define _APS_NEXT_SYMED_VALUE           110\r
+#endif\r
+#endif\r
diff --git a/Tools/win/DLLLauncher/DLLLauncherMain.cpp b/Tools/win/DLLLauncher/DLLLauncherMain.cpp
new file mode 100644 (file)
index 0000000..bd1ce43
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This file contains code for a launcher executable for WebKit apps. When compiled into foo.exe, it
+// will set PATH so that Apple Application Support DLLs can be found, then will load foo.dll and
+// call its dllLauncherEntryPoint function, which should be declared like so:
+//     extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstCmdLine, int nCmdShow);
+
+#include <shlwapi.h>
+#include <string>
+#include <vector>
+#include <windows.h>
+
+using namespace std;
+
+static void enableTerminationOnHeapCorruption()
+{
+    // Enable termination on heap corruption on OSes that support it (Vista and XPSP3).
+    // http://msdn.microsoft.com/en-us/library/aa366705(VS.85).aspx
+
+    HEAP_INFORMATION_CLASS heapEnableTerminationOnCorruption = static_cast<HEAP_INFORMATION_CLASS>(1);
+
+    HMODULE module = ::GetModuleHandleW(L"kernel32.dll");
+    if (!module)
+        return;
+
+    typedef BOOL (WINAPI*HSI)(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T);
+    HSI heapSetInformation = reinterpret_cast<HSI>(::GetProcAddress(module, "HeapSetInformation"));
+    if (!heapSetInformation)
+        return;
+
+    heapSetInformation(0, heapEnableTerminationOnCorruption, 0, 0);
+}
+
+static wstring getStringValue(HKEY key, const wstring& valueName)
+{
+    DWORD type = 0;
+    DWORD bufferSize = 0;
+    if (::RegQueryValueExW(key, valueName.c_str(), 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
+        return wstring();
+
+    vector<wchar_t> buffer(bufferSize / sizeof(wchar_t));
+    if (::RegQueryValueExW(key, valueName.c_str(), 0, &type, reinterpret_cast<LPBYTE>(&buffer[0]), &bufferSize) != ERROR_SUCCESS)
+        return wstring();
+
+    return &buffer[0];
+}
+
+static wstring applePathFromRegistry(const wstring& key, const wstring& value)
+{
+    HKEY applePathKey = 0;
+    if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &applePathKey) != ERROR_SUCCESS)
+        return wstring();
+    wstring path = getStringValue(applePathKey, value);
+    ::RegCloseKey(applePathKey);
+    return path;
+}
+
+static wstring appleApplicationSupportDirectory()
+{
+    return applePathFromRegistry(L"SOFTWARE\\Apple Inc.\\Apple Application Support", L"InstallDir");
+}
+
+static wstring copyEnvironmentVariable(const wstring& variable)
+{
+    DWORD length = ::GetEnvironmentVariableW(variable.c_str(), 0, 0);
+    if (!length)
+        return wstring();
+    vector<wchar_t> buffer(length);
+    if (!GetEnvironmentVariable(variable.c_str(), &buffer[0], buffer.size()) || !buffer[0])
+        return wstring();
+    return &buffer[0];
+}
+
+static bool prependPath(const wstring& directoryToPrepend)
+{
+    wstring pathVariable = L"PATH";
+    wstring oldPath = copyEnvironmentVariable(pathVariable);
+    wstring newPath = directoryToPrepend + L';' + oldPath;
+    return ::SetEnvironmentVariableW(pathVariable.c_str(), newPath.c_str());
+}
+
+static int fatalError(const wstring& programName, const wstring& message)
+{
+    wstring caption = programName + L" can't open.";
+    ::MessageBoxW(0, message.c_str(), caption.c_str(), MB_ICONERROR);
+    return 1;
+}
+
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpstrCmdLine, int nCmdShow)
+{
+    enableTerminationOnHeapCorruption();
+
+    // Get the path of our executable.
+    wchar_t exePath[MAX_PATH];
+    if (!::GetModuleFileNameW(0, exePath, _countof(exePath)))
+        return fatalError(L"Unknown Program", L"Failed to determine name of executable.");
+
+    ::PathRemoveExtensionW(exePath);
+
+    wstring programName = ::PathFindFileNameW(exePath);
+
+    wstring aasDirectory = appleApplicationSupportDirectory();
+    if (aasDirectory.empty())
+        return fatalError(programName, L"Failed to determine path to Apple Application Support directory.");
+    if (!prependPath(aasDirectory))
+        return fatalError(programName, L"Failed to modify PATH environment variable.");
+
+    // Load our corresponding DLL.
+    wstring dllName = programName + L".dll";
+    if (!::PathRemoveFileSpecW(exePath))
+        return fatalError(programName, L"::PathRemoveFileSpecW failed.");
+    if (!::PathAppendW(exePath, dllName.c_str()))
+        return fatalError(programName, L"::PathAppendW failed.");
+    HMODULE module = ::LoadLibraryW(exePath);
+    if (!module)
+        return fatalError(programName, L"::LoadLibraryW failed.");
+
+    typedef int (WINAPI*EntryPoint)(HINSTANCE, HINSTANCE, LPWSTR, int);
+    EntryPoint entryPoint = reinterpret_cast<EntryPoint>(::GetProcAddress(module, "_dllLauncherEntryPoint@16"));
+    if (!entryPoint)
+        return fatalError(programName, L"Failed to find dllLauncherEntryPoint function.");
+
+    return entryPoint(hInstance, hPrevInstance, lpstrCmdLine, nCmdShow);
+}