Determine Dll Types Programatically

How can you programmatically determin if a dll is an assembly, win32 or activex?

[87 byte] By [SethMaffey] at [2008-2-15]
# 1
If you just want to find out if a file is an assembly you can use AssemblyName.GetAssemblyName which will throw a BadImageFormatException if the file is not a valid assembly.
DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

That is helpful. My goal is to programatically determine if a given DLL is one of the following:

  • .NET Assembly so I know it can be gac'd using gacutil.exe (If needed)
  • ActiveX DLL so I know it needs to be registered using regsvr32
  • Win32 so I know it needs to be in the current directory or the system path.

The AssemblyName.getAssemblyName helps, though I would prefer it to be a handled function rather than determining that it isn't an assembly because it threw an exception.

I have read that there is a PE header and it has some logic to it but I am unfamiliar with the header to make any use of it.

Any ideas are appreciated.

Thanks

SethMaffey at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Hmm...I agree..this would be a common necessity. Also with the 64-bit version being added, differntiating between 32-bit and 64-bit DLLs, x64 and Itanium would also come into picture.

I feel Microsoft needs to add a API or methods to the .NET Framework to address this need.

Regards,
Vikram

Vikram at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Thanks for the feedback.

I double checked with our team and there is no API call in .NET that can give you this information. You would need to write custom code to crack open the DLLs and see what they are.

I've passed this on to the product team for consideration in future versions. If you have the time and interest, I suggest you file a suggestion on the product feedback center and reply with the ID number.

Thanks again.

Paul Yuknewicz

PaulYuk_MS at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...