c# - 从 C#(64 位)加载 C++ 类库

标签 c# c++ windows 32bit-64bit badimageformatexception

我有一个 C++ 类库和一个使用该库的 C# Windows 应用程序。

它在 32 位 Windows 上运行良好,但在 64 位 Windows 上运行不佳 - BadImageFormatException 发生了。

我尝试更改C++类库的平台,但是无法从WIN32更改为WIN64。

我认为以下问题之一可以解决这个问题。

  1. 有没有办法将 WIN32 库转换为 WIN64 库?
  2. 有没有其他方法可以在不使用 C++ 库的情况下在 C# 上调用 C++ 函数?
  3. 是否可以在 64 位应用程序中加载 WIN32 库?

最佳答案

Is there a way to convert WIN32 Library to WIN64 Library?

将库重建(重新编译)为 64 位库。

Is it possible to load WIN32 Library in 64 bit application?

没有。来自 Programming Guide for 64-bit Windows :

... 32-bit processes cannot load 64-bit DLLs for execution, and 64-bit processes cannot load 32-bit DLLs for execution.

关于c# - 从 C#(64 位)加载 C++ 类库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13124535/

相关文章:

android - Calabash-Android 运行文件未找到

c# - 控制台应用程序的 log4net 配置

c# - 在 Direct X 11 游戏中挂接 Direct X Endscene

c++ - 手动调用构造函数?

android - 在 PATH 中找不到程序 "g++"

windows - Python 可执行文件 : py2exe or PyInstaller?

C# Environment.GetEnvironmentVariable(...) 不适用于 OSX

c# - 在运行时计算类代码的哈希值 (C#)?

c++ - 如何修复 C++ 中结构的段错误?

c++ - 检查函数指针是否被注册