SDK: execute C# directly


Does anyone know if there’s a way to execute C# code directly from the SDK?

Currently I’m using MXS as an interop, sending a script from SDK to MXS, and then having MXS execute the C# and return any compiler warnings/errors/etc.

Is there a more direct way of doing this?

Imagine I want to execute the following C# code:

float f = Math.Abs(-1.0f);

and have the value pass back to C++. Is it possible? I know how to do it with MXS, but I want to cut out the middleman.


in project settings you have to have General::Common Language Runtime Support set to Common Language Runtime Support (/clr)

then you can use stuff like

#using <System.dll> 

using namespace System;
using namespace System::IO;
using namespace System::Net;
using namespace System::Text;
using namespace msclr::interop;

at the top of the file, any includes


it can look quite funky in a cpp file…

WebRequest^ request = WebRequest::Create(marshal_as<String^>(url));

marshal_context^ context = gcnew marshal_context();
string*  result = new string(context->marshal_as<const char*>(responseFromServer));

theres also a couple of pragmas too

#pragma unmanaged
#pragma managed

though it does beg the question what’s in the c# runtime that not in cpp runtime,? I’m sure I saw some absolute functions last time i looked :wink:


Thanks Klvnk, I’ll look further into that :slight_smile: