diff options
author | George Hazan <ghazan@miranda.im> | 2018-07-31 17:51:37 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-07-31 17:51:37 +0300 |
commit | 2b6d90564fa3cf379cfd57dfbfdf4cf750e994b1 (patch) | |
tree | 42276091fc22e825eb1cf60f5c8fade8cfaa03e6 | |
parent | 29077096131fad5026780272a870a4a07bad76d2 (diff) |
exe loader extracted to the separate module, now it's possible to compile all exe using shared runtime modules
-rw-r--r-- | build/appstub/appstub.cpp | 37 | ||||
-rw-r--r-- | plugins/MimCmd/MimCmd.vcxproj | 9 | ||||
-rw-r--r-- | plugins/MimCmd/src/MimCmd.cpp | 3 | ||||
-rw-r--r-- | plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj | 12 | ||||
-rw-r--r-- | src/miranda32/miranda32.vcxproj | 8 | ||||
-rw-r--r-- | src/miranda32/src/miranda.cpp | 27 |
6 files changed, 52 insertions, 44 deletions
diff --git a/build/appstub/appstub.cpp b/build/appstub/appstub.cpp new file mode 100644 index 0000000000..67e4159c8e --- /dev/null +++ b/build/appstub/appstub.cpp @@ -0,0 +1,37 @@ +#include <Windows.h> + +#include <delayimp.h> +#pragma comment(lib, "delayimp.lib") + +static HANDLE hUcrtDll = nullptr; + +EXTERN_C HANDLE WINAPI hook(unsigned mode, PDelayLoadInfo) +{ + if (mode == dliNotePreLoadLibrary && hUcrtDll == nullptr) { + wchar_t wszPath[MAX_PATH]; + GetModuleFileNameW(nullptr, wszPath, _countof(wszPath)); + + // if current dir isn't set + for (int i = lstrlenW(wszPath); i >= 0; i--) + if (wszPath[i] == '\\') { + wszPath[i] = 0; + break; + } + + SetCurrentDirectoryW(wszPath); + + lstrcatW(wszPath, L"\\libs"); + SetDllDirectoryW(wszPath); + +#ifdef _DEBUG + lstrcatW(wszPath, L"\\ucrtbased.dll"); +#else + lstrcatW(wszPath, L"\\ucrtbase.dll"); +#endif + hUcrtDll = LoadLibraryW(wszPath); + } + + return 0; +} + +EXTERN_C const PfnDliHook __pfnDliNotifyHook2 = (PfnDliHook)&hook; diff --git a/plugins/MimCmd/MimCmd.vcxproj b/plugins/MimCmd/MimCmd.vcxproj index a6f3088b44..9ba7bd360c 100644 --- a/plugins/MimCmd/MimCmd.vcxproj +++ b/plugins/MimCmd/MimCmd.vcxproj @@ -31,15 +31,10 @@ <ItemDefinitionGroup>
<Link>
<SubSystem>Console</SubSystem>
- <DelayLoadDLLs>mir_core.mir</DelayLoadDLLs>
+ <DelayLoadDLLs Condition="'$(Configuration)'=='Debug'">mir_core.mir;ucrtbased.dll;vcruntime140.dll</DelayLoadDLLs>
+ <DelayLoadDLLs Condition="'$(Configuration)'=='Release'">mir_core.mir;ucrtbase.dll;api-ms-win-crt-string-l1-1-0.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;VCRUNTIME140.dll</DelayLoadDLLs>
</Link>
<ClCompile>
- <RuntimeLibrary Condition="'$(Configuration)'=='Debug'">MultiThreadedDebug</RuntimeLibrary>
- </ClCompile>
- <ClCompile>
- <RuntimeLibrary Condition="'$(Configuration)'=='Release'">MultiThreaded</RuntimeLibrary>
- </ClCompile>
- <ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
</ItemDefinitionGroup>
diff --git a/plugins/MimCmd/src/MimCmd.cpp b/plugins/MimCmd/src/MimCmd.cpp index 384c79b8d1..91271d17ae 100644 --- a/plugins/MimCmd/src/MimCmd.cpp +++ b/plugins/MimCmd/src/MimCmd.cpp @@ -19,8 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "stdafx.h"
-
-#pragma comment(lib, "delayimp.lib")
+#include "..\..\build\appstub\appstub.cpp"
wchar_t* GetProgramName(wchar_t *programName, size_t size)
{
diff --git a/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj b/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj index 5f87eff746..4a8b9283dc 100644 --- a/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj +++ b/plugins/PluginUpdater/pu_stub/pu_stub_15.vcxproj @@ -90,12 +90,13 @@ <WarningLevel>Level4</WarningLevel> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers> + <DelayLoadDLLs>ucrtbased.dll;vcruntime140.dll</DelayLoadDLLs> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> @@ -103,11 +104,12 @@ <WarningLevel>Level4</WarningLevel> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> + <DelayLoadDLLs>ucrtbased.dll;vcruntime140.dll</DelayLoadDLLs> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -118,13 +120,14 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> + <DelayLoadDLLs>ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;vcruntime140.DLL</DelayLoadDLLs> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -134,13 +137,14 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <FavorSizeOrSpeed>Size</FavorSizeOrSpeed> - <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> + <DelayLoadDLLs>ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;vcruntime140.DLL</DelayLoadDLLs> </Link> </ItemDefinitionGroup> <ItemGroup> diff --git a/src/miranda32/miranda32.vcxproj b/src/miranda32/miranda32.vcxproj index 07b5c41cc1..de61c97157 100644 --- a/src/miranda32/miranda32.vcxproj +++ b/src/miranda32/miranda32.vcxproj @@ -39,14 +39,10 @@ <Manifest>
<AdditionalManifestFiles>res/miranda32.exe.manifest</AdditionalManifestFiles>
</Manifest>
- <ClCompile>
- <RuntimeLibrary Condition="'$(Configuration)'=='Debug'">MultiThreadedDebug</RuntimeLibrary>
- </ClCompile>
- <ClCompile>
- <RuntimeLibrary Condition="'$(Configuration)'=='Release'">MultiThreaded</RuntimeLibrary>
- </ClCompile>
<Link>
<AdditionalManifestDependencies>type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 processorArchitecture=%27*%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27;type=%27win32%27 name=%27Microsoft.Windows.Gdiplus%27 version=%271.0.0.0%27 processorArchitecture=%27*%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27;%(AdditionalManifestDependencies)</AdditionalManifestDependencies>
+ <DelayLoadDLLs Condition="'$(Configuration)'=='Debug'">ucrtbased.dll;vcruntime140.dll</DelayLoadDLLs>
+ <DelayLoadDLLs Condition="'$(Configuration)'=='Release'">ucrtbase.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;VCRUNTIME140.dll</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
</Project>
\ No newline at end of file diff --git a/src/miranda32/src/miranda.cpp b/src/miranda32/src/miranda.cpp index cf13b17cb0..97bc1f467b 100644 --- a/src/miranda32/src/miranda.cpp +++ b/src/miranda32/src/miranda.cpp @@ -23,8 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "stdafx.h"
-
-#pragma comment(lib, "delayimp.lib")
+#include "..\..\build\appstub\appstub.cpp"
typedef int (WINAPI *pfnMain)(LPTSTR);
@@ -36,30 +35,8 @@ const wchar_t wszRuntimeUrl[] = L"https://download.visualstudio.microsoft.com/do const wchar_t wszQuestion[] = L"Miranda NG needs the Visual Studio runtime library, but it cannot be loaded. Do you want to load it from Inernet?";
-int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int)
+int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPTSTR cmdLine, int)
{
- wchar_t wszPath[MAX_PATH];
- GetModuleFileNameW(hInstance, wszPath, _countof(wszPath));
-
- // if current dir isn't set
- for (int i = lstrlenW(wszPath); i >= 0; i--)
- if (wszPath[i] == '\\') {
- wszPath[i] = 0;
- break;
- }
-
- SetCurrentDirectoryW(wszPath);
-
- lstrcatW(wszPath, L"\\libs");
- SetDllDirectoryW(wszPath);
-
- #ifdef _DEBUG
- lstrcatW(wszPath, L"\\ucrtbased.dll");
- #else
- lstrcatW(wszPath, L"\\ucrtbase.dll");
- #endif
- LoadLibraryW(wszPath);
-
int retVal;
HINSTANCE hMirApp = LoadLibraryW(L"mir_app.mir");
if (hMirApp == nullptr) {
|