值为anycpu / 86/64为C#应用程序,它是C ++ / CLI依赖 [英] AnyCPU/x86/x64 for C# application and it's C++/CLI dependency

查看:326
本文介绍了值为anycpu / 86/64为C#应用程序,它是C ++ / CLI依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows开发者,我使用Microsoft Visual Studio 2008 SP1。我开发的机器是64位的。

I'm Windows developer, I'm using Microsoft visual studio 2008 SP1. My developer machine is 64 bit.

我目前正在对软件进行管理的.exe用C#编写。不幸的是,我无法来解决整个问题只是在C#。这就是为什么我还开发了一个小的托管DLL在C ++ / CLI。这两个项目都在同一个解决方案。

The software I'm currently working on is managed .exe written in C#. Unfortunately, I was unable to solve the whole problem solely in C#. That's why I also developed a small managed DLL in C++/CLI. Both projects are in the same solution.

我的C#的.exe建设的目标是任何CPU。当我的C ++动态链接库构建的目标是86,该DLL没有加载。 据我了解,当我用Google搜索,其原因是C ++ / CLI语言,不像其他.NET语言,编译为本地code,不是管理code。

My C# .exe build target is "Any CPU". When my C++ DLL build target is "x86", the DLL is not loaded. As far as I understood when I googled, the reason is C++/CLI language, unlike other .NET languages, compiles to the native code, not managed code.

我换了C ++ DLL构建目标到x64,和一切正常了。但是,AFAIK一切都会停止,一旦工作作为我的客户将在32位操作系统上安装我的产品。我要支持Windows Vista和7,32位和64位版本,他们每个人。

I switched the C++ DLL build target to x64, and everything works now. However, AFAIK everything will stop working as soon as my client will install my product on a 32-bit OS. I have to support Windows Vista and 7, both 32 and 64 bit versions of each of them.

我不想回落到32位。这250行C ++ code在我的DLL是只有2%我codeBase的。而该DLL仅用于在几个地方,因此在典型的使用场景它甚至没有装载

I don't want to fall back to 32 bits. That 250 lines of C++ code in my DLL is only 2% of my codebase. And that DLL is only used in several places, so in the typical usage scenario it's not even loaded.

我的DLL实现与ATL两个COM对象,所以我不能用的 / CLR:安全项目设置

My DLL implements two COM objects with ATL, so I can't use "/clr:safe" project setting.

有没有方法来配置解决方案和项目,使C#项目建立任何CPU的版本中,C ++项目构建的两个 32位和64位版本,然后在运行时管理的时候.EXE正在启动,它采用32位的DLL或64位的DLL取决于操作系统?

Is there way to configure the solution and the projects so that C# project builds "Any CPU" version, the C++ project builds both 32 bit and 64 bit versions, then in the runtime when the managed .EXE is starting up, it uses either 32-bit DLL or 64-bit DLL depending on the OS?

或者,也许有一些更好的解决方案,我不知道呢?

Or maybe there's some better solution I'm not aware of?

在此先感谢!

推荐答案

哦,原来没有简单的方法。如果你有本地code(即你的C ++),你需要支持的x86,那么你必须编译的x86(除非你想工作在WOW的世界......即在32上运行32位code位和64位envrionments)。您可以同时具有x86和x64发行版,但如果你同时支持32位和64位,而你本地code或COM introp那么你的必须有32位和64位二进制文​​件。 任何CPU唯一真正有用时,有没有原生code或互操作,那么你得到的benifit。

There is no easy way around it. If you have native code (i.e. your C++) and you need to support x86, then you have to compile x86 (unless you want to work in WOW world...ie. running 32 bit code in both 32 and 64 bit envrionments). You can have both an x86 and x64 distributions, but if you're supporting both 32 and 64 bit, and you have native code or COM introp' then you have to have both 32 and 64 bit binaries. "Any CPU" only really is useful when there is no native code or interop, then you get that benifit.

这篇关于值为anycpu / 86/64为C#应用程序,它是C ++ / CLI依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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