I'm building a C# application that loads a 32-bit COM dll. The compiled application runs fine on 32-bit Windows but barfs on 64 bit Windows because it can't load the 32-bit COM. Is there a way to set a 32-bit build target in VC# 2008 Express Edition?
Alternatively, is there a way to force a .NET application compiled to the AnyCPU build target to run in 32-bit mode on 64-bit Windows?
You cannot explicitly set it to 32-bit in the UI in VS Express, but apparently (I only have the Professional version at hand) it can be done using a bit of setting up. This forum post has details on how to do it.
What you can also do is to use the CorFlags tool that comes with the .Net Framework SDK to set the compiled output to run as 32-bit. To set the 32-bit flag using CorFlags, run this from the command line:
CorFlags.exe /32BIT+ yourapp.exe
This will set a flag in the header of your exe to signal to .Net that it should be run as 32-bit.
For posterity, here is the forum post adrian linked to:
In VC# Express, this property is
missing, but you can still create an
x86 configuration if you know where to
look.
It looks like a long list of steps,
but once you know where these things
are it's a lot easier. Anyone who only
has VC# Express will probably find
this useful. Once you know about
Configuration Manager, it'll be much
more intuitive the next time.
- In VC# Express 2005, go to Tools -> Options.
- In the bottom-left corner of the Options dialog, check the box that
says, "Show all settings".
- In the tree-view on the left hand side, select "Projects and Solutions".
- In the options on the right, check the box that says, "Show advanced
build configuraions."
- Click OK.
- Go to Build -> Configuration Manager...
- In the Platform column next to your project, click the combobox and select
"".
- In the "New platform" setting, choose "x86".
- Click OK.
- Click Close.
There, now you have an x86
configuration! Easy as pie! :-)
I also recommend using Configuration
Manager to delete the Any CPU
platform. You really don't want that
if you ever have depedencies on 32-bit
native DLLs (even indirect
dependencies).