I have a C# program that needs to copy over a user provided dll for another program to load and use. In the case of the program running on a 64 bit machine, the user should not be allowed to pass a 32 bit dll and should inform the user that they’ve provided an incorrect dll. So how can I find the architecture of a dll?
I saw a couple similar questions and they mentioned DUMPBIN and Corflags.exe, but there is no example code, so where do I find these programs and how do I use these?
Code example
This is the complete code of a
C#console application that can detectdllarchitectures that also includes the ones you wanted.Using Corflags…
You wrote about this and, just to know, this will help you to get some information regarding your assembly (
dll) but this is notC#! this is a tool that can be used inVisual Studioconsole.Just open
Visual Studioconsole and use this command:This will be the output:
Then, focus on
PE:PE32, this will describe your assembly architecture:So, according to this…
AnyCPU means -> PE: PE32 -> 32BIT: 0
x86 means -> PE: PE32 -> 32BIT: 1
x64 means -> PE: PE32+ -> 32BIT: 0
The architecture of
MyAssembly.dllis32bitIdea…
Well, if you want to simplify all this, an idea could be to create a background process using
C#then in the arguments use the command I gave you above and print the output ofPE:XXto get the assembly architecture and according to that value tell your application what to do.I just made some research, hope this helps 🙂