views:

65

answers:

3

Hello,

I'm trying to install and run a 32 bit application on a Win7 x64 machine. The application is built as a Win32 app. It runs fine on 32 bit platforms. On the x64 machine it installs correctly in the Programs(x86) directory and runs fine until I make a call into a 32 bit dll. At that time I get the incorrect format error (0x8007000b) indicating it is trying to load the dll of the wrong bitness. Indeed it is trying to load the 64 bit dll from the System32 directory rather than the 32 bit version in the SystemWOW64 directory.

Another 32 bit application provided by the dll vendor runs correctly and it does load the 32 bit dll from the SystemWOW64 directory. I do not have source to their application to see how they are accessing the DLL.

I'm using the DllImport function as shown below to access the dll. Is there a way to decorate the DllImport calls to force it to load the 32 bit version?

Any thoughts appreciated.

Thanks, DP

public static class Micronas
{
    [DllImport(@"UAC2.DLL")]
    public static extern short UacBuildDeviceList(uint uFlags);
    [DllImport(@"UAC2.DLL")]
    public static extern short UacGetNumberOfDevices();
    [DllImport(@"UAC2.DLL")]
    public static extern uint UacGetFirstDevice();
    [DllImport(@"UAC2.DLL")]
    public static extern uint UacGetNextDevice(uint handle);
    [DllImport(@"UAC2.DLL")]
    public static extern uint UacSetXDFP(uint handle, short adr, uint data);
    [DllImport(@"UAC2.DLL")]
    public unsafe static extern uint UacGetXDFP(uint handle, short adr, IntPtr data);
}
A: 

Since your post is tagged with C#, I'm assuming this is a .NET app. It's probably not being set 32-bit only. You can verify by running corflags.exe on it, and setting the 32-bit only flag on it with corflags /32bit+ myapp.exe. If that fixes it, you need to fix your solution/project to build as x86 instead of Any CPU.

Bob
thanks for the suggestions. You're correct that it is a .NET app and it includes a number of DLLs. The DLLs support COM Interop, if that has any bearing. The DllImport code above is in one of the DLLs of the project. The projects were rebuilt w/ the x86 flag and I tried corflags as well to no avail.One thing that is interesting is that I built a new C# project, and used the DllImport code above with no problems, i.e. it loaded the 32 bit version correctly. I guess my next step is to try a new DLL to see if that works.
DFP
+1  A: 

Force your .exe to run in 32-bit mode. Project + Properties, Build tab, Platform Target = x86.

Avoid getting confused by the project's Platform setting, it doesn't actually have to match the real setting. Which is Project + Properties, Build tab, Platform Target. Bit of a mess there.

Hans Passant
A: 

In order to force the application to run in 32-bit mode on 64-bit platform you can set it in IIS application pool: in advanced settings set "Enable 32-bits applications" to TRUE.

Petr Kozelek