Skip to content

Commit

Permalink
Statically link to CRT in Release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
poiru committed Dec 26, 2015
1 parent 60823ff commit 84f673b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
34 changes: 1 addition & 33 deletions Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,6 @@ WCHAR* GetCommandLineArguments()
return args;
}

/*
** Attempts to load Rainmeter.dll. If it fails, retries after loading our own copies of the CRT
** DLLs in the Runtime directory.
*/
HINSTANCE LoadRainmeterLibrary()
{
HINSTANCE rmDll = LoadLibrary(L"Rainmeter.dll");
if (!rmDll)
{
WCHAR path[MAX_PATH];
if (GetModuleFileName(nullptr, path, MAX_PATH) > 0)
{
PathRemoveFileSpec(path);
PathAppend(path, L"Runtime");
SetDllDirectory(path);
PathAppend(path, L"msvcp120.dll");

// Loading msvcpNNN.dll will load msvcrNNN.dll as well.
HINSTANCE msvcrDll = LoadLibrary(path);
SetDllDirectory(L"");

if (msvcrDll)
{
rmDll = LoadLibrary(L"Rainmeter.dll");
FreeLibrary(msvcrDll);
}
}
}

return rmDll;
}

/*
** Entry point. In Release builds, the entry point is Main() since the CRT is not used.
**
Expand All @@ -97,7 +65,7 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
HRSRC iconResource = FindResource(instance, MAKEINTRESOURCE(1), RT_ICON);
if (iconResource)
{
HINSTANCE rmDll = LoadRainmeterLibrary();
HINSTANCE rmDll = LoadLibrary(L"Rainmeter.dll");
if (rmDll)
{
auto rainmeterMain = (RainmeterMainFunc)GetProcAddress(rmDll, MAKEINTRESOURCEA(1));
Expand Down
6 changes: 1 addition & 5 deletions Build/Installer/Installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,6 @@ FunctionEnd

SetOutPath "$INSTDIR\Plugins"
File /x *Example*.dll "..\..\${DIR}-Release\Plugins\*.dll"

SetOutPath "$INSTDIR\Runtime"
File "$%VS140COMNTOOLS%..\..\VC\redist\${ARCH}\Microsoft.VC140.CRT\msvcp140.dll"
File "$%VS140COMNTOOLS%..\..\VC\redist\${ARCH}\Microsoft.VC140.CRT\vcruntime140.dll"
File "$%VS140COMNTOOLS%..\..\..\Windows Kits\10\Redist\ucrt\DLLs\${ARCH}\*.dll"
!macroend

!macro RemoveStartMenuShortcuts STARTMENUPATH
Expand Down Expand Up @@ -629,6 +624,7 @@ SkipIniMove:
Delete "$INSTDIR\Defaults\Plugins\FileView.dll"
RMDir /r "$INSTDIR\Addons\Rainstaller"
RMDir /r "$INSTDIR\Addons\RainBackup"
RMDir /r "$INSTDIR\Runtime"

${If} $InstallPortable <> 1
CreateDirectory "$INSTDIR\Defaults"
Expand Down
1 change: 1 addition & 0 deletions Build/VS/Rainmeter.Cpp.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<!-- Set WINVER=0x0601 and friends (Win7) to avoid using Win8 specific features in the Win8 SDK. -->
<!-- Set _HAS_EXCEPTIONS=0 to accompany the disabled exception handling above. -->
<PreprocessorDefinitions>WIN32;_WINDOWS;WINVER=0x0601;_WIN32_WINNT=0x0601;_WIN32_IE=0x0601;PSAPI_VERSION=1;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary Condition="'$(Configuration)'=='Release'">MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
Expand Down

0 comments on commit 84f673b

Please sign in to comment.