我试图延迟为C++/CLI应用程序加载我的依赖.dll,以便我可以测试它们的存在并警告用户,而不是仅仅崩溃。如何延迟在C++ - CLI(.net)应用程序中加载.dll文件?
我试着添加DLL文件MyProject->属性 - > ConfigurationProperties->连接器 - >输入 - >延迟加载的DLL ...但只是给我一个警告,它不是引用它们:
5> LINK:警告LNK4199:/DELAYLOAD:Util.dll忽略;无论从Util.dll
发现如果我删除一个.dll并运行它崩溃,并希望将信息发送到微软关于失踪的.dll的应用程序,它看起来像它仍然在尝试通过加载所有的模块进口因此启动和适应。
仅供参考,我的应用程序启动时看起来是这样的:
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);
}
}
...
“IL”代表什么?我怀疑这可能是比它值得的更多的努力,从你所说的话,它可能是。 – 2011-01-21 16:09:04