在 64 位环境中使用 32 位程序集 [英] Use a 32-bit assembly in 64-bit environment

查看:44
本文介绍了在 64 位环境中使用 32 位程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 DevIL.NET 集成到 3ds Max 中以自动将我的图像转换为单一格式.为此,我在 C# 中创建了一个接受字符串并返回新文件路径的类库

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
    }
}

该项目引用了 DevIL.NET,它是一个 32 位版本.我的应用程序是 64 位版本,并给出了 BadImageFormatException.说它"不是有效的 Win32 应用程序.

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.

我已经尝试通过在 .csproj 文件中添加额外的一行来使我的应用程序成为 32 位:x86.这样,我的测试项目可以运行,但我的类库不起作用,因为 3ds Max 是 64 位应用程序.

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.

如何将这些 32-64 个问题排列起来,以便我的插件可以工作?鉴于 3ds Max 将是 64 位,而 DevIL.NET 将是 32 位.我似乎无法从 VC++ Express 2008 的源代码中自己构建 64 位的 DevIL.NET.

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.

推荐答案

您不能将一个位"的 DLL 加载到作为另一个位"运行的进程中.你所能做的就是调整平台或在它自己的进程中运行另一个位"DLL.

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.

对于接受插件的 64 位应用程序,我不得不这样做一次.我创建了一个 64 位 shim DLL,它进入应用程序并通过 IPC 与 32 位进程对话.由于第三方 DLL 也是 32 位,因此需要此 32 位进程.

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.

这在背面是一种适当的痛苦,但不幸的是,由于当时其他供应商没有 64 位支持,因此这是必需的痛苦.

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.

您可以使用 .NET 中的 Process 相关类从 64 位 shim 控制其他 32 位进程 - 这实际上是我最终要做的.

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.

这篇关于在 64 位环境中使用 32 位程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆