views:

36

answers:

1

I have a .NET app that is dependent on a native DLL. I have the .NET app set as AnyCPU. In the post-build step, I plan to copy the correct native DLL from some directory (x86 or AMD64) and place it in the target path.

However, this doesn't work. On a 64-bit machine, the environment variable PROCESSOR_ARCHITECTURE is "x86" in Visual Studio.

My alternative right now is to create a small tool that outputs the processor architecture. This will be used by the post-build step.

Is there a better alternative?

(Side Note: when deploying/packaging the app, the right native DLL is copied to the right platform. But this means we have two separate release folders for x86 and AMD64, which is OK since this is for a device driver. The app is a utility tool for the driver).

+1  A: 

Visual Studio is 32bit application and thus runs in the WoW64 layer on 64bit systems. I assume that is why PROCESSOR_ARCHITECTURE yields "x86" in there - compatibility: the app should really think it is a 32bit system.

You could check for the presence and value of the PROCESSOR_ARCHITEW6432 variable, which will bei AMD64 even if the actual application is executed under WoW64. Note that this variable does not exist on 32bit Windows and is also not defined for 64bit processes on 64bit Windows.

Christian.K