32 位 dllimport 在 win7 x64 平台上生成不正确的格式错误 (0x8007000b)

发布于 2024-09-14 23:16:03 字数 1068 浏览 2 评论 0原文

我正在尝试在 Win7 x64 计算机上安装并运行 32 位应用程序。该应用程序构建为 Win32 应用程序。它在 32 位平台上运行良好。在 x64 机器上,它正确安装在 Programs(x86) 目录中,并且运行良好,直到我调用 32 位 dll。当时我收到错误格式错误(0x8007000b),表明它正在尝试加载错误位数的 dll。事实上,它试图从 System32 目录加载 64 位 dll,而不是 SystemWOW64 目录中的 32 位版本。

dll 供应商提供的另一个 32 位应用程序运行正常,并且确实从 SystemWOW64 目录加载 32 位 dll。我没有他们的应用程序的源代码来了解他们如何访问 DLL。

我正在使用如下所示的 DllImport 函数来访问 dll。有没有办法装饰 DllImport 调用以强制它加载 32 位版本?

任何想法表示赞赏。

谢谢,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);
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月朦胧 2024-09-21 23:16:03

强制您的 .exe 以 32 位模式运行。项目 + 属性,构建选项卡,平台目标 = x86。

避免对项目的平台设置感到困惑,它实际上不必与真实设置相匹配。这是“项目+属性”、“构建”选项卡、“平台目标”。那里有点乱。

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.

青丝拂面 2024-09-21 23:16:03

由于您的帖子带有 C# 标签,我假设这是一个 .NET 应用程序。它可能不只设置为 32 位。您可以通过在其上运行 corflags.exe 并使用 corflags /32bit+ myapp.exe 设置仅 32 位标志来进行验证。如果问题解决了,您需要修复您的解决方案/项目以构建为 x86 而不是任何 CPU。

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.

若有似无的小暗淡 2024-09-21 23:16:03

为了强制应用程序在 64 位平台上以 32 位模式运行,您可以在 IIS 应用程序池中进行设置:在高级设置中将“启用 32 位应用程序”设置为 TRUE。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文