Search code examples
.net32bit-64bit3dsmaxdevil

Use a 32-bit assembly in 64-bit environment


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.


Solution

  • 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.