1
votes

i'm exploring the idea of use .net as a scripting language for my program.

i found a lot of examples on internet that shows how to host .net and then, from c++ call functions from .net.

But i need to go on the other way too, from this code in c#, i need to be able to create/call c++'s objects from this c# script, so i need to expose functions/objects to control it from C#.

How can i do it?

Simple Example to show what i'm talking about I call my c++ method "CreateGUI". It'll call .net code: "InitializeGUI", and this "InitializeGUI" need to check if an object (for example, the texture) is instantiated inside C++.

Can someone help me?

Thanks!

2
Write managed wrappers for your C++ classes with the C++/CLI language. See stackoverflow.com/questions/2691325/… for an example. - Hans Passant
Hm, I'd love to know how do you want to use ".Net as a scripting language for your program..." - Paul Michalik

2 Answers

0
votes

If you use managed C++, you can create a managed C++ component which can be called from your C# code. If you use unmanaged C++, you can either create a C++ COM component and use it through C# via RCW (Runtime Callable Wrapper) mechanism or you can create a C++ dll and call it from C# via PInvoke.

0
votes

You might also investigate Mono, which is explicitly intended to be embedded and will run any compiled .NET assembly, meaning the full powers of C#, VB.NET, even F# will be available.