反向 PInvoke 并创建完整的非托管 C# 程序

发布于 2024-09-01 07:46:20 字数 257 浏览 1 评论 0原文

我知道这是一个奇怪的问题,但想法很简单:我更喜欢 C# 语法而不是 C++: - 直接在属性内部设置和获取方法 - 接口 -foreach 语句 - 可以声明隐式强制转换运算符

其他小事情...

我真正不知道的是,如果我不使用任何命名空间(甚至系统),是否可以在 C# 中导入 c++ dll(特别是 std 库

)想法只是使用 C++ 中通常使用的所有内容(没有来自 CLR 的内容)编写一个程序,甚至例如 printf

感谢您的回答

I know this is a strange question but the idea is simple: I prefer C# syntax rather than C++:
-Setters and getters directly inside a property
-interfaces
-foreach statement
-possibility to declare an implicit cast operator

other small things...

What I really don't know is if is possible to import a c++ dll (expecially std libraries) in C# if I don't use any namespace (even System)

The idea is just to write a program using everything that you will normally use in C++ (nothing from CLR so), even printf for example

Thanks for any answer

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

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

发布评论

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

评论(3

甜尕妞 2024-09-08 07:46:20

不,不可能简单地将现有 C 或 C++ 文件导入到 C# 项目中。它们是非常不同的语言,不能在源代码级别混合。

混合 C# 和 C++/C 应用程序的方法是在 PInvoke 或 COM 互操作级别。这是通过复制 C# 中的签名并允许 C# 编译器确定本机类型的二进制布局来实现的,以便在语言之间进行封送。

No it is not possible to simply import existing C or C++ files into a C# project. They are very different languages and cannot be mixed at the source level.

The way to mix C# and C++/C applications is at the PInvoke or COM Interop level. This works by duplicating the signatures in C# and allowing the C# compiler to determine the binary layout of the native type in order to marshal between the languages.

风渺 2024-09-08 07:46:20

现在有一些与此接近的东西

.NET Native 将 C# 编译为本机代码,其执行方式类似于C++。您将继续受益于 .NET Framework 的生产力和熟悉度以及本机代码的出色性能。

它仅适用于 Windows 应用商店应用程序(桌面应用程序将来可能会出现):

桌面应用程序是我们战略中非常重要的一部分。最初,我们专注于使用 .NET Native 的 Windows 应用商店应用程序。从长远来看,我们将继续改进所有 .NET 应用程序的本机编译。

应用程序将作为完全独立的本机编译代码部署在最终用户设备上(当 .NET Native 进入生产环境时),并且不会依赖于目标设备/计算机上的 .NET Framework

There's now something close to this

.NET Native compiles C# to native machine code that performs like C++. You will continue to benefit from the productivity and familiarity of the .NET Framework with the great performance of native code.

It's for Windows Store apps only (desktop apps may come in the future):

Desktop apps are a very important part of our strategy. Initially, we are focusing on Windows Store apps with .NET Native. In the longer term we will continue to improve native compilation for all .NET applications.

And

apps will get deployed on end-user devices as fully self-contained natively compiled code (when .NET Native enters production), and will not have a dependency on the .NET Framework on the target device/machine

撑一把青伞 2024-09-08 07:46:20

不;这不是直接可能的。特别是,C# 不支持 C++ 模板。

No; this is not directly possible. In particular, C++ templates are not supported by C#.

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