Visual Studio 2008 Express C++ Windows 7 64 位上的 32 位构建

发布于 2024-10-31 08:17:05 字数 637 浏览 1 评论 0原文

我正在使用 Visual Studio 2008 Express。我有一个在 Vista 32 位上运行良好的解决方案。我最近切换到 Windows 7,其中一部分停止工作。这是我的设置: - 非托管 C++ 静态库,“库” - 托管 C++ DLL,包装“库”的功能以在 C# 中使用,“DLL” - 引用“DLL”的托管 C++ 控制台应用程序 - 引用“DLL”的 C# 应用程序

在运行 C# 应用程序时,我收到 DLL 抛出的异常,并且我通常通过托管 C++ 控制台应用程序调试此类问题,因为这样我就可以单步执行非托管库代码。

问题是我现在收到一个弹出对话框,其中包含一些奇怪的符号和“C:\Windows\Microsoft.NET\Framework\v2.0.50727\dw20.exe”的路径,然后是我的应用程序当我尝试运行托管 C++ 控制台应用程序时,捕获抛出的异常“System.BadImageFormatException:不是有效的 Win32 应用程序”。我花了很多时间研究这个问题,任何哪怕是一点点有用的建议都指的是用 C# 构建 X86 项目,而不是 C++。我尝试将 /MACHINE:X86 添加到库的 Librarian 选项中,但这似乎不起作用。

我想简而言之,我的问题是,如何确保构建我的非托管 C++ 静态库,以便它可以在 32 位系统上运行?

I am using Visual Studio 2008 Express. I have a solution which used to work fine on Vista 32 bit. I recently switched over to Windows 7, and part of it stopped working. This is my setup:
- Unmanaged C++ static library, "the library"
- Managed C++ DLL that wraps functionality of "the library" for use in C#, "the DLL"
- Managed C++ console application that references "the DLL"
- C# application that references "the DLL"

I am getting an exception thrown by the DLL when running the C# application, and I usually debug problems like that through the managed C++ console app, since I can then step into the unmanaged library code.

The problem is that I now get a popup dialog with some weird symbols and the path to "C:\Windows\Microsoft.NET\Framework\v2.0.50727\dw20.exe", and then my app catches an exception "System.BadImageFormatException: is not a valid Win32 application" thrown when I try to run the managed C++ console app. I have spent a lot of time researching this issue, and anything that even remotely resembles useful advice refers to building X86 projects in C#, but nothing about C++. I tried adding /MACHINE:X86 to the Librarian options of the library, but that doesn't seem to work.

I guess in short my question is, how do I get to make sure my unmanaged C++ static library builds so that it can run on 32 bit systems?

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

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

发布评论

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

评论(2

贱人配狗天长地久 2024-11-07 08:17:05

dw20.exe 程序是“Doctor Watson”,该程序报告未处理的运行时异常和崩溃。不是问题的根源,只是问题的使者。尽管问题中没有说明,但我必须假设您的 Windows 7 版本是 64 位,这是 System.BadImageFormatException 的常见来源。

该异常是由 64 位进程尝试加载为 32 位构建的 DLL 引起的。或者反过来,32 位进程无法加载 64 位 DLL。进程的位数由 EXE(在您的情况下是 C++/CLI 应用程序)决定。它无法像 C# 项目那样通过简单的项目设置来更改它。您可以通过添加平台来实现,“x64”使用 64 位编译器并生成 64 位可执行文件。我很确定这在 C++ Express 版本中不可用,但您没有 64 位编译器,因此必须始终生成 32 位可执行文件。

这使得解释异常的空间很小。仅当您更改 C# 类库项目中的平台目标设置时,才可能出错。从 x86 或 AnyCPU 到 x64。将其改回 AnyCPU。项目+属性,构建选项卡。如果您采取了任何措施来解决 Express 版本的限制,例如从 SDK 版本中添加 64 位编译器,那么这也将是问题根源的一个主要危险信号。

The dw20.exe program is "Doctor Watson", the program that reports unhandled runtime exceptions and crashes. Not the source of the problem, merely the messenger. Although unstated in the question, I have to assume your Windows 7 version is 64-bit, the common source of System.BadImageFormatException.

The exception is caused by a 64-bit process trying to load a DLL that was built for 32-bit. Or the other way around, a 32-bit process cannot load a 64-bit DLL. The bitness of the process is determined by the EXE, a C++/CLI app in your case. It doesn't have the option to change it with a simple project setting, like C# projects do. You do it by adding a platform, "x64" uses the 64-bit compiler and generates a 64-bit executable. I'm pretty sure that is not available in the C++ Express edition though, you don't have the 64-bit compilers so must always generate a 32-bit executable.

Which leaves very little room to explain the exception. It could only go wrong if you changed the Platform target setting in your C# class library project. From x86 or AnyCPU to x64. Change it back to AnyCPU. Project + Properties, Build tab. If you have done anything to hack around the limitations of the Express edition, like adding 64-bit compilers from an SDK release then that would be a major red flag for the source of the problem as well.

哭了丶谁疼 2024-11-07 08:17:05

将构建从 Any CPU 更改为 32 或 86,应该没有问题。您可能在 C++ 代码中使用 Windows 32 DLL,这就是它无法在其他平台上工作的原因。
任何CPU->配置管理器然后更改为32或86

Change the built from Any CPU to 32 or 86, and you should have no problem. you probably are using in the c++ code a windows 32 dll that's why it doesn't work on other platforms.
Any CPU-> configuration Manager then change to 32 or 86

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