As anyone who has been looking at my blog knows, I have been mostly working on VS integration of the test tools used in our team (apart from setting up and managing TFS for the builds and various other initiatives.)
Anyway, so, I started to author a project template for VS. What's a project without a wizard? So, there is a wizard where you input some basic information and it will generate skeleton test classes, test areas, setup the references, the target platform etc.
The crux of the issue is, the wizard is 32bit. However, it needs to setup the project to target 32bit or 64bit. Depending on the target, the references to the core test infrastructure assemblies have to be added. However, the setup for the test infrastructure will add keys in the following pattern:
There is the issue. Let us suppose, I am targetting the 64bit platform from my 32bit wizard. The wizard has to know that the installation folder for the x64 binaries reside in the folder pointed to by the value of the key HKLM\SOFTWARE\Microsoft\Mantis\x64\InstallDir. AFAIK, to do this correctly, the wizard has to figure out whether it is executing as a 32bit binary on WoW64 or as a 32bit binary on a 32bit machine.
After a lot of digging around and playing around with an interop layer (and not being successful I might add), I figured out a solution. I have replicated the code below (it is provided AS-IS).
/// Interop layer to get information about the host system.
public sealed class SystemInfo
/// Maps to the native processor architecture values.
public enum ProcessorArchitecture : int
None = -1,
Intel = 0,
IA64 = 6,
AMD64 = 9
#region Private Data
/// The native system info instance.
private SystemInfoNative nativeInfo;
/// Initializes a new instance of the class.
/// The native system info.
private SystemInfo ( SystemInfoNative nativeInfo )
this.nativeInfo = nativeInfo;
/// Gets the processor architecture.
/// The processor architecture.
public ProcessorArchitecture Architecture
return (ProcessorArchitecture) Enum.Parse ( typeof ( ProcessorArchitecture ),
Enum.GetName ( typeof ( ProcessorArchitecture ),
this.nativeInfo.processorArchitecture ) );
#region Static Methods
/// Gets the native system info.
public static SystemInfo GetNativeSystemInfo ()
SystemInfoNative native = new SystemInfoNative ();
GetNativeSystemInfo ( ref native );
return new SystemInfo ( native );
[StructLayout ( LayoutKind.Sequential )]
private struct SystemInfoNative
internal ushort processorArchitecture;
private ushort reserved;
internal uint pageSize;
internal IntPtr minimumApplicationAddress;
internal IntPtr maximumApplicationAddress;
internal IntPtr activeProcessorMask;
internal uint numberOfProcessors;
internal uint processorType;
internal uint allocationGranularity;
internal ushort processorLevel;
internal ushort processorRevision;
[DllImport ( "kernel32.dll" )]
private static extern void GetNativeSystemInfo ( ref SystemInfoNative lpSystemInfo );
PingBack from http://hoursfunnywallpaper.cn/?p=2371