diff --git a/Engine/source/main/main.cpp b/Engine/source/main/main.cpp index fbc97226a..a1d2bd1f1 100644 --- a/Engine/source/main/main.cpp +++ b/Engine/source/main/main.cpp @@ -32,29 +32,49 @@ extern "C" int (*torque_winmain)( HINSTANCE hInstance, HINSTANCE h, LPSTR lpszCmdLine, int nShow) = NULL; }; -bool getDllName(std::wstring& dllName) +bool getDllName(std::wstring& dllName, const std::wstring suffix) { wchar_t filenameBuf[MAX_PATH]; DWORD length = GetModuleFileNameW( NULL, filenameBuf, MAX_PATH ); if(length == 0) return false; dllName = std::wstring(filenameBuf); size_t dotPos = dllName.find_last_of(L"."); - if(dotPos == std::wstring::npos) return false; + if(dotPos == std::wstring::npos) + { + dllName.clear(); + return false; + } dllName.erase(dotPos); - dllName += L".dll"; + dllName += suffix + L".dll"; return true; } int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCommandShow) { + // Try to find the game DLL, which may have one of several file names. + HMODULE hGame = NULL; std::wstring dllName = std::wstring(); - if(!getDllName(dllName)) + // The file name is the same as this executable's name, plus a suffix. + const std::wstring dllSuffices[] = {L"", L" DLL"}; + const unsigned int numSuffices = sizeof(dllSuffices) / sizeof(std::wstring); + + for (unsigned int i = 0; i < numSuffices; i++) + { + // Attempt to glue the suffix onto the current filename. + if(!getDllName(dllName, dllSuffices[i])) + continue; + // Load the DLL at that address. + hGame = LoadLibraryW(dllName.c_str()); + if (hGame) + break; + } + + if(!dllName.length()) { MessageBoxW(NULL, L"Unable to find game dll", L"Error", MB_OK|MB_ICONWARNING); return -1; } - HMODULE hGame = LoadLibraryW(dllName.c_str()); if (!hGame) { wchar_t error[4096]; diff --git a/Tools/projectGenerator/templates/vc2010_dll_proj.tpl b/Tools/projectGenerator/templates/vc2010_dll_proj.tpl index cd520d051..a134420f1 100644 --- a/Tools/projectGenerator/templates/vc2010_dll_proj.tpl +++ b/Tools/projectGenerator/templates/vc2010_dll_proj.tpl @@ -50,15 +50,15 @@ {$projectOffset}../../{$gameFolder}/ {$projectOffset}../Link/VC2010.$(Configuration).$(PlatformName)/$(ProjectName)/ true - {$projOutName}_DEBUG + {$projOutName}_DEBUG DLL {$projectOffset}../../{$gameFolder}/ {$projectOffset}../Link/VC2010.$(Configuration).$(PlatformName)/$(ProjectName)/ false - {$projOutName}_OPTIMIZEDDEBUG + {$projOutName}_OPTIMIZEDDEBUG DLL {$projectOffset}../../{$gameFolder}/ {$projectOffset}../Link/VC2010.$(Configuration).$(PlatformName)/$(ProjectName)/ false - {$projOutName} + {$projOutName} DLL @@ -96,7 +96,7 @@ {foreach item=def from=$projLibsDebug}{$def};{/foreach}%(AdditionalDependencies) - $(OutDir){$projOutName}_DEBUG.dll + $(OutDir)$(TargetName).dll true {foreach item=def from=$projLibDirs}{$def};{/foreach}{$projectOffset}../Link/VC2010.$(Configuration).$(PlatformName);$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) LIBC;LIBCD;{foreach item=def from=$projLibsIgnore}{$def};{/foreach}%(IgnoreSpecificDefaultLibraries) @@ -148,7 +148,7 @@ {foreach item=def from=$projLibsDebug}{$def};{/foreach}%(AdditionalDependencies) - $(OutDir){$projOutName}_OPTIMIZEDDEBUG.dll + $(OutDir)$(TargetName).dll true {foreach item=def from=$projLibDirs}{$def};{/foreach}{$projectOffset}../Link/VC2010.$(Configuration).$(PlatformName);%(AdditionalLibraryDirectories) LIBC;LIBCD;{foreach item=def from=$projLibsIgnore}{$def};{/foreach}%(IgnoreSpecificDefaultLibraries) @@ -200,7 +200,7 @@ {foreach item=def from=$projLibs}{$def};{/foreach}%(AdditionalDependencies) - $(OutDir){$projOutName}.dll + $(OutDir)$(TargetName).dll true {foreach item=def from=$projLibDirs}{$def};{/foreach}{$projectOffset}../Link/VC2010.$(Configuration).$(PlatformName);$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) LIBC;LIBCD;{foreach item=def from=$projLibsIgnore}{$def};{/foreach}%(IgnoreSpecificDefaultLibraries) diff --git a/Tools/projectGenerator/templates/vc2k8_dll_proj.tpl b/Tools/projectGenerator/templates/vc2k8_dll_proj.tpl index f9d02a7eb..e255fc0f4 100644 --- a/Tools/projectGenerator/templates/vc2k8_dll_proj.tpl +++ b/Tools/projectGenerator/templates/vc2k8_dll_proj.tpl @@ -81,9 +81,9 @@ AdditionalDependencies="{foreach item=def from=$projLibsDebug}{$def} {/foreach}" {if $uniformOutputFile eq 1} - OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName}.dll" + OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName} DLL.dll" {else} - OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName}_DEBUG.dll" + OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName}_DEBUG DLL.dll" {/if} LinkIncremental="2" @@ -191,9 +191,9 @@ AdditionalDependencies="{foreach item=def from=$projLibsDebug}{$def} {/foreach}" {if $uniformOutputFile eq 1} - OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName}.dll" + OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName} DLL.dll" {else} - OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName}_OPTIMIZEDDEBUG.dll" + OutputFile="{$projectOffset}../../{$gameFolder}/{$projOutName}_OPTIMIZEDDEBUG DLL.dll" {/if} LinkIncremental="1" @@ -299,7 +299,7 @@