First, I can see you're a bit confused about .NET part of getting version information. The method
GetFileVersionInfo
only gets file version. The versioning system of .NET software is usually based on assembly version, which is totally independent from the file version and is defined by the assembly attribute
AssemblyVersion
and the file version is defined by the assembly attribute
AssemblyFileVersion
.
Suppose you load an assembly from file. Here is how you get the version:
System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFrom(fileName);
System.Version version =
assembly.GetName().Version;
Now, let's approach getting assembly by the Win32 unmanaged code. I suggest you work around the problem. First, create a .NET assembly which retrieve the
System.Version
information from the assemblies the way you want. It should clone this type into some managed type understandable by your unmanaged code.
Now, the problem is to deliver the result to the unmanaged code. You will need to create some static managed method in you library assembly and export it as unmanaged; and the unmanaged code should be able to load this library as a regular unmanaged DLL and call this method.
Many would say this is impossible. This is almost true but not all the truth. It is only impossible in C# or VB.NET, but quite possible using IL assembler; and this is a part of CLR ECMA and ISO standards, not like any dirty trick.
So, the idea is to use a special attribute to mark the methods to be exported as unmanaged. The code is complied by VB.NET or C#, disassembled; then the IL code is modified according to the attributes and assembled again. This is automated using the MSBuild custom step, so no knowledge of IL assembler is required.
You can find the solution in the following CodeProject articles:
Unmanaged code can wrap managed methods[
^],
How to Automate Exporting .NET Function to Unmanaged Programs[
^].
[EDIT]
Same approach goes for getting a public key token of assembly strong name. You can get it using your .NET library DLL. Use
System.Reflection.Assembly.GetName().GetPublicKeyToken
, see
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.aspx[
^].
—SA