4

I am trying to integrate DevIL.NET into 3ds Max to automatically convert my images to a single format. To do so, I created a class library in C# that accepts a string and returns the new file path

public static class FileConverter
{
    public static string ConvertFile(string _sOriginal)
    {
        // Load the file, save the file, return the new filepath
    }
}

The project is referencing to DevIL.NET, which is a 32-bit build. My application is a 64-bit build and gives a BadImageFormatException. Saying that "it" is not a valid Win32 application.

I have already tried to make my application 32-bit by adding an extra line in the .csproj file: <PlatformTarget>x86</PlatformTarget>. In this way, my test project does work, but my class library doesn't, because 3ds Max is a 64-bit application.

How is it possible to line these 32-64 problems up, so that my plugin will work? Given is that 3ds Max will be 64-bit and DevIL.NET will be 32-bit. I can't seem to build DevIL.NET in 64 bit myself from source in VC++ Express 2008.

Marnix
  • 6,384
  • 4
  • 43
  • 78

2 Answers2

5

You cannot load a DLL of one "bitness" into a process running as another "bitness". All you can do to solve the problem is align the platforms or run the other "bitness" DLL in it's own process.

I had to do this once for a 64-bit application that accepted plug-ins. I created a 64-bit shim DLL that went into the application and talked to a 32-bit process via IPC. This 32-bit process was required due to a third-party DLL also being 32-bit.

It was a proper pain in the backside, but unfortunately a required pain as the other vendor didn't have 64-bit support at that time.

You can control this other 32-bit process from your 64-bit shim using the Process related classes in .NET - this is actually what I ended up doing.

Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
  • Would it be a good idea to try to build the DevIL.NET wrapper myself in a 64-bit environment? The DevIL.dll that is wrapped is also available for 64-bit. So I think that this will align everything in 64-bits, right? – Marnix Jul 19 '11 at 09:04
  • 1
    If you can get this other DLL to be 64-bit, then you can compile your own code in AnyCPU and it should all then work. That would be the best approach. – Adam Houldsworth Jul 19 '11 at 09:15
0

You can't mix 32 bit code and 64 bit code in the same process. You'll need to use two processes by one means or another, or find a way to use all 32 bit or all 64 bit.

The express versions of Visual Studio do not support 64 bit targets. If you purchase the standard version then you may be able to recompile the plug-in in 64 bit mode. Note however, that it may not be that simple because you may need to modify the code in case it contains assumptions about bitness.

A possibly easier option would be to use the 32 bit version of 3ds.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490