我正在尝试延迟加载C++/CLI应用程序的依赖.dll文件,以便我可以测试其是否存在并警告用户,而不是直接崩溃。我已经尝试将dll文件添加到MyProject->属性->配置属性->链接器->输入->延迟加载DLLS中...但这只会给我一个警告,表示它没有引用它们:
5>LINK : warning LNK4199: /DELAYLOAD:Util.dll ignored; no imports found from Util.dll
如果我删除一个.dll文件并运行应用程序,它就会崩溃,并要求向Microsoft发送有关缺少.dll文件的信息,因此看起来它仍然在启动时尝试加载所有模块,并因此出现问题。
FYI,我的应用程序启动看起来像这样:
5>LINK : warning LNK4199: /DELAYLOAD:Util.dll ignored; no imports found from Util.dll
如果我删除一个.dll文件并运行应用程序,它就会崩溃,并要求向Microsoft发送有关缺少.dll文件的信息,因此看起来它仍然在启动时尝试加载所有模块,并因此出现问题。
FYI,我的应用程序启动看起来像这样:
using namespace System;
using namespace System::Collections::ObjectModel;
using namespace Microsoft::Win32;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
try
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// First make sure we have all the .dlls we need
ArrayList^ missingDlls = gcnew ArrayList();
Assembly^ assembly = Assembly::GetEntryAssembly();
array<System::Reflection::AssemblyName^>^ referencedAssemblies = assembly->GetReferencedAssemblies();
for each(System::Reflection::AssemblyName^ referencedAssemblyName in referencedAssemblies)
{
try
{
Assembly^ a = assembly->Load(referencedAssemblyName);
if( a == nullptr )
{
missingDlls->Add(referencedAssemblyName->Name);
}
}
catch(System::Exception^ e)
{
MessageBox::Show("Error loading "+referencedAssemblyName->Name);
}
}
...