Why C# is not allowing non-member functions like C++

See this blog posting: http://blogs.msdn.com/ericlippert/archive/2009/06/22/why-doesn-t-c-implement-top-level-methods.aspx (…) I am asked “why doesn’t C# implement feature X?” all the time. The answer is always the same: because no one ever designed, specified, implemented, tested, documented and shipped that feature. All six of those things are necessary to make a feature happen. All of them cost huge amounts … Read more

No IntelliSense for C++/CLI in Visual Studio 2010?

You are correct. Unfortunately it has been dropped. You can check this opened issue on Microsoft’s Connect website. I’ll just quote them for the sake of the answer: Unfortunately in this release we had to cut the intellisense support for C++/CLI due to time constraints. If you want to get some intellisense like quick info … Read more

c++/cli pass (managed) delegate to unmanaged code

Yes, you want Marshal::GetFunctionPointerForDelegate(). Your code snippet is missing the managed function you’d want to call, I just made one up. You will also have to declare the managed delegate type and create an instance of it before you can get a function pointer. This worked well: #include “stdafx.h” using namespace System; using namespace System::Runtime::InteropServices; … Read more

How to call a C# library from Native C++ (using C++\CLI and IJW)

You can do this fairly easily. Create an .h/.cpp combo Enable /clr on the newly create .cpp file. (CPP -> Right click -> Properties) Set the search path for “additional #using directories” to point towards your C# dll. Native.h void NativeWrapMethod(); Native.cpp #using <mscorlib.dll> #using <MyNet.dll> using namespace MyNetNameSpace; void NativeWrapMethod() { MyNetNameSpace::MyManagedClass::Method(); // static … Read more

Using C++ Class DLL in C# Application

Simple way assuming class Foo: Create a C++/CLI project, call this FooWrapper. Make FooWrapper depend on the unmanaged dll (however you normally would). Create a managed class ManagedFoo which contains a single private instance field of type Foo*. provide public wrapping functions in ManagedFoo which forward on to the underlying instance field. Optionally (though recommended): … Read more

Calling C# code from C++, but ExecuteInDefaultAppDomain() is too limited

There are several ways for a C++ application to invoke functions in a C# DLL. Using C++/CLI as an intermediate DLL http://blogs.microsoft.co.il/sasha/2008/02/16/net-to-c-bridge/ Reverse P/Invoke http://tigerang.blogspot.ca/2008/09/reverse-pinvoke.html http://blogs.msdn.com/b/junfeng/archive/2008/01/28/reverse-p-invoke-and-exception.aspx Using COM http://msdn.microsoft.com/en-us/library/zsfww439.aspx Using CLR Hosting (ICLRRuntimeHost::ExecuteInDefaultAppDomain()) http://msdn.microsoft.com/en-us/library/dd380850%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/ms164411%28v=vs.110%29.aspx https://stackoverflow.com/a/4283104/184528 Interprocess communication (IPC) How to remote invoke another process method from C# application http://www.codeproject.com/Tips/420582/Inter-Process-Communication-between-Csharp-and-Cpl Edit: Host a HTTP server … Read more

C++/CLI Mixed Mode DLL Creation

Well, no, it doesn’t get to be mix-mode until you tell the C++/CLI compiler that your legacy DLL was written in unmanaged code. Which should have been noticeable, you should have gotten linker errors from the unmanaged DLL exports. You need to use #pragma managed: #pragma managed(push, off) #include “oldskool.h” #pragma comment(lib, “oldskool.lib”) #pragma managed(pop) … Read more