如何从 Windows Server 2003 64 位版本上运行的 C# 调用 32 位 C DLL?

发布于 2024-08-11 18:20:11 字数 377 浏览 1 评论 0原文

我知道我无法使用默认的“平台目标:任何 CPU”构建设置来编译我的 C# 代码并调用 32 位 C DLL。但是,如果我将此设置更改为“平台目标:x86”,C# 代码应该在 32 位上下文下运行并在该 32 位上下文下调用 C DLL,对吧?虽然看起来并没有什么作用。

我是否必须使用一些特殊的注册表或其他东西来注册 32 位 C DLL?

我使用的是 Windows Server 2003 64 位。

错误是:

Runtime Error!
[Path to dll]
R6034
An application has made an attempt to load the C runtime library incorrectly.

I know I can’t compile my C# code using the default ”Platform Target : Any CPU” build setting and call a 32 bit C DLL. But if I change this setting to ”Platform Target : x86” the C# code should run under a 32-bit context and call the C DLL under that 32 bit context right? Although it doesn’t seem to work.

Do I have to register the 32-bit C DLL with some special registry or something?

I am using Windows Server 2003 64 bit.

The error is:

Runtime Error!
[Path to dll]
R6034
An application has made an attempt to load the C runtime library incorrectly.

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

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

发布评论

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

评论(1

絕版丫頭 2024-08-18 18:20:11

你是对的。如果您使用设置为 x86 的平台进行构建,则您的 32 位 DLL 应该可以正常工作。

如果不是,请检查以下事项:

  1. 确保 DLL 是可发现的。这通常意味着将其包含在与应用程序的 EXE 相同的文件夹中。
  2. 确保 DLL 所需的所有依赖项在系统上都存在(并且可发现)。这通常意味着安装正确的 VC++ 可再发行组件。
  3. 如果您使用 32 位 COM 组件,请确保在系统上注册该组件。

编辑:看到您的评论后,您的问题是由于 DLL 没有正确的清单。如果您在 DLL 中嵌入清单,它应该能够正确解析正确的 C 运行时并加载它(前提是部署计算机上安装了正确的运行时。)

You are correct. If you're building with the platform set to x86, your 32bit DLL should work fine.

If it's not, here are some things to check:

  1. Make sure the DLL is discoverable. This usually means including it in the same folder as your application's EXE.
  2. Make sure all of the dependencies required by your DLL exist (and are discoverable) on the system. This often means installing the correct VC++ redistributable.
  3. If you're using a 32bit COM component, make sure to register the component on the system.

Edit: After seeing your comment, your issue is due to the DLL not having a proper manifest. If you embed a manifest in the DLL, it should be able to properly resolve the correct C runtime, and load it (provided the correct runtime is installed on the deployment machine.)

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