Use a 32-bit assembly in 64-bit environment

不问归期 提交于 2019-12-01 06:50:09

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6744284/use-a-32-bit-assembly-in-64-bit-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!