Reverse PInvoke and create a full unmanaged C# pro

2019-07-06 22:38发布

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

3条回答
家丑人穷心不美
2楼-- · 2019-07-06 22:40

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

查看更多
劫难
3楼-- · 2019-07-06 22:49

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

查看更多
戒情不戒烟
4楼-- · 2019-07-06 23:01

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.

查看更多
登录 后发表回答