C# - 混合程序集(C++/CLI、DirectX 原生)交互(32/64 位) [英] C# - mixed assembly (C++/CLI, DirectX native) interplay (32/64bit)

查看:27
本文介绍了C# - 混合程序集(C++/CLI、DirectX 原生)交互(32/64 位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与相关的问题问题.两名球员:

I have a problem related to this question. Two players:

  1. C# 应用程序
  2. 1) 使用的混合程序集

应用程序必须支持从 Windows XP(32 位)到 Windows 7(32 位和 64 位)的任何内容.组装以不同的方式复杂.它包含托管 C++/CLI 代码和一些与本机 DirectX 共舞的本机 C++ 类.它还链接到一些 32 位本机 dll 的无源访问(包含带有导入库的 C++ 类).

The application has to support anything from Windows XP (32bit) to Windows 7 (32 & 64bit). The assembly is complicated in different ways. It contains managed C++/CLI code and some native C++ classes dancing with native DirectX. It also is linked to a few 32bit native dll's w/o source access (containing C++ classes with import libraries).

一切在 32 位环境(XP 和 7 测试)中运行良好,包括 Windows 7 上的 32 位子系统.一旦在 64 位系统上使用任何 CPU"以构建完整的解决方案,就会发生严重破坏.32 位程序集不可用 - 但似乎仅在调试模式下(无法加载,格式错误"等).似乎可以发布.对上述 32 位第三方 dll 的隐式依赖关系阻止了 64 位程序集构建.

Things are working well in 32bit environments (XP and 7 tested) including the 32bit subsystem on Windows 7. Havoc happens, as soon as "Any CPU" is used on 64bit systems in order to build the complete solution. The 32bit assembly is unusable than - but seemingly only in debug mode ("cannot load, wrong format" etc.). It seems to work in release. A 64bit assembly build is prevented by the implicit dependencies to the mentioned 32bit third-party dll's.

有没有办法提供一个真正的原生 64 位应用程序能够使用该程序集?

Is there any way to provide a real native 64bit application able to use the assembly?

对程序集的要求并不那么严格.它可以同时是 32 位或 64 位,但如上所述,应该可以从应用程序中以一种或另一种方式使用.

Requirement for the assembly isn't that strict. It could be both - 32 or 64bit - but as said above, should be be usable from the application one way or the other.

推荐答案

您在 64 位版本的 Windows 中遇到了一个严酷的限制,64 位进程无法在进程内执行任何 32 位机器代码.当您使用 C++/CLI 并使用 DirectX 时,您肯定会依赖于机器代码.虽然听起来你不能在 64 位模式下执行,但 C++/CLI 和 DirectX 都可以在 64 位中编译/可用.

You are running into a rock hard limitation in the 64-bit version of Windows, a 64-bit process cannot execute any 32-bit machine code in-process. You certainly have a dependency on machine code when you use C++/CLI and work with DirectX. Although it doesn't sound like you could not execute in 64-bit mode, both C++/CLI and DirectX can be compiled/are available in 64-bit.

这归结为构建和部署问题.您必须在 64 位模式下构建 C++/CLI 项目,并在 64 位操作系统上部署 64 位组件.主 EXE 必须构建到 AnyCPU.同样,在 32 位操作系统上,您必须仅构建和部署 32 位编译版本.您可以通过将 x64 配置添加到解决方案来解决构建问题,以便分别构建 32 位和 64 位版本.您可以通过创建两个安装程序来解决部署问题.

This then boils down to a build and deployment issue. You have to build the C++/CLI project(s) in 64-bit mode and deploy only 64-bit components on a 64-bit operating system. The main EXE must be built to AnyCPU. Similarly, on a 32-bit operating system you must build and deploy only the 32-bit compiled version. You solve the build issue by adding the x64 configuration to the solution so you build the 32-bit and 64-bit version separately. You solve the deployment issue by creating two installers.

因为无论如何您都必须支持 32 位操作系统,所以简单的解决方案是将您的 EXE 项目 上的目标平台设置更改为 x86.现在一切都在 32 位模式下运行,您不必为构建和部署烦恼.您唯一错过的是 64 位版本中可用的更大的虚拟内存地址空间.

Since you have to support a 32-bit operating system anyway, the simple solution is to change the Target platform setting on your EXE project to x86. Now everything always runs in 32-bit mode and you don't have to bother with the build and deployment headaches. The only thing you miss out on is the larger virtual memory address space that's available in the 64-bit version.

这篇关于C# - 混合程序集(C++/CLI、DirectX 原生)交互(32/64 位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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