News for hackers. Stuff that matters.
Re:Running C++ code from C# Dotnet Core by HippoBaro on Friday August 17, 2018 @06:05PM (#17785791)
This is arguably not C++ interoperability, but C interop. Big difference there. The author conveniently doesn't show how to pass parameters (especially non-POCO objects), for example.
Re:Running C++ code from C# Dotnet Core by snarfy on Friday August 17, 2018 @06:33PM (#17785890)
Yeah, I saw the title and was excited, then I saw

    #ifdef __cplusplus
    extern "C" {
    #endif

This makes it C interop.

If it were C++ interop, I would be able to DllImport a C++ library (without the C linkage) and get a C# wrapper class of the C++ classes automatically.

It's not C#'s fault. C++ is the one without an ABI. To properly DllImport C++ you would need to define the so/dll name in the import and also the specific C++ compiler version and build, since the binary changes underneath, e.g. foo.msvc_x64_debug.dll, foo.gcc_x86_release.dll, etc. Then C# might have a chance of importing a c++ library, but not today.

Re:Running C++ code from C# Dotnet Core by sebazzz on Saturday August 18, 2018 @01:40AM (#17787048)
> If it were C++ interop, I would be able to DllImport a C++ library (without the C linkage) and get a C# wrapper class of the C++ classes automatically.

If you count COM as being C++, it would be possible.

Re:Running C++ code from C# Dotnet Core by zamalek on Friday August 17, 2018 @06:27PM (#17785873)
Exactly.

It should be theoretically be possible to call C++ via interop:

    [DllImport("<MANGLED NAME>")]
    static extern void Foo(IntPtr @this, int param1, ...);
Re:Running C++ code from C# Dotnet Core by sebazzz on Saturday August 18, 2018 @01:35AM (#17787029)
That will only work on x64 I believe. x86 requires the this pointer to be passed in register ECX [0]

[0]: https://docs.microsoft.com/en-us/cpp/cpp/thiscall

Re:Running C++ code from C# Dotnet Core by zamalek on Saturday August 18, 2018 @02:00AM (#17787109)
I studied calling conventions too long ago, but wasn't ECX (registers and then stack, in general) stdcall on Windows? I could stand to absolute correction there, just curious.
Re:Running C++ code from C# Dotnet Core by thebillkidy on Saturday August 18, 2018 @01:56PM (#17789654)
[Author] Thanks for pointing this out! Seeing I am quite new to this as well, I was not aware of this. Will check this out!