问题描述
我有c#程序使用Microsoft.Dism.DLL来收集驱动程序信息。
I have c# program use Microsoft.Dism.DLL to gather driver info.
以下是问题所在:
当64位操作系统(Win10)上的32位程序调用DismApi.GetDrivers()时抛出以下异常。
It throw following exception when 32bit program call DismApi.GetDrivers() on 64-bit OS (Win10).
例外:捕获异常:Microsoft.Dism.dll中的"Microsoft.Dism.DismException"("尝试加载格式不正确的程序。")。捕获到异常:Microsoft.Dism.dll中的"Microsoft.Dism.DismException"("尝试加载具有不正确格式的程序的
。")
Exception: Exception caught: 'Microsoft.Dism.DismException' in Microsoft.Dism.dll ("An attempt was made to load a program with an incorrect format."). Exception caught: 'Microsoft.Dism.DismException' in Microsoft.Dism.dll ("An attempt was made to load a program with an incorrect format.")
更改以下构建设置后,此异常消失:
This exception disappeared after I changed following build settings:
平台目标: 86  - >任何CPU
Platform Target: x86 --> Any CPU
首选32位:未选中。
但是在Win7 64bit上调用DismApi.Initialize()时,同样的32位程序会抛出BadImageFormatException。
But the same 32bit program throws BadImageFormatException when call DismApi.Initialize() on a Win7 64bit.
问题: Microsoft.Dism.DLL是32位还是64位?为什么我的解决方案适用于Win 10但在Win 7上失败?谢谢。
Question: Is Microsoft.Dism.DLL 32bit or 64bit? Why my solution works on Win 10 but fails on Win 7? Thanks.
推荐答案
感谢您在此发帖。
对于你的问题,你可以使用反射来得到你想要的东西。
For your question, you could use reflection to get what you want.
请尝试下面的代码。
System.Reflection.AssemblyName.GetAssemblyName("Microsoft.Dism.dll");
检查ProcessorArchitecture的价值 参数可以获得处理器和可执行文件所针对的平台的每字节数。
Check the value of ProcessorArchitecture parameter could get the processor and bits-per-word of the platform targeted by an executable.
MSIL表示处理器和每字位数的中性。这意味着任何CPU。
MSIL represents neutral with respect to processor and bits-per-word. It means Any CPU.
有关 ProcessorArchitecture 枚举的更多详细信息,请参阅MSDN文档。
For more details about the ProcessorArchitecture Enumeration, please refer to the MSDN documents.
最好的问候,
Wendy
这篇关于32位程序在64位操作系统问题上加载Microsoft.Dism.DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!