问题描述
我正在编写C ++ / CLI应用程序,但我希望C ++ DLL中的大多数代码都可以本机运行(即不受管理)。
I'm writing a C++ / CLI application, but I want most of the code in my C++ DLL to run natively (i.e. not managed).
在模块中只有一个CLI类,其他文件都是本机C ++。
I have only got a single CLI class in the module, the other files are all native C++.
因此,确保这些本机类运行的最佳方法是什么。
So, what is the best way of ensuring that those native classes are run... Well, natively?
我应该:
- A)添加#pragma不受管理地排在每个本机类的顶部
- B)只需在我的单个CLI类中的包含之前添加#pragma不受管理的
- A) Add #pragma unmanaged to the top of every native class
- B) Just add #pragma unmanaged before the includes in my single CLI class
- C) Something else?
谢谢
推荐答案
您不必跳过障碍即可确保这一点。只有在打开/ clr选项的情况下编译程序时,编译器才会发出IL。它看起来像项目选项,但不是。
You don't have to jump through hoops to ensure this. The compiler will only ever emit IL when it compiles your program with the /clr option turned on. It looks like a project option but it is not.
只需选择包含本机代码的.cpp文件即可。按住Ctrl键并在资源管理器窗口中单击文件,以选择其中一个以上的文件。右键单击+属性,C / C ++,常规。将公共语言运行时支持设置更改为否...。
Just select your .cpp files that contain native code. Select more than one of them by holding down the Ctrl key and clicking the file in the Explorer windows. Right-click + Properties, C/C++, General. Change the "Common Language Runtime Support" setting to "No...".
这篇关于C ++ CLI正确使用#pragma托管/非托管的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!