-1

Possible Duplicate:
Is it possible to make a call to a C# application from a C++ application?

I am playing with the idea of writing a proof of concept application that contains a script engine that runs (executes) a .CLI language (e.g. C#, VB.Net etc).

I had originally wanted to create the script engine application in C++, but that appears to be fraught with problems and work arounds. Instead, I want to write the script engine in C# instead now.

I have sketched together a very rough idea of what it is I'm trying to do below:

The code is still pseudo C++, but hopefully, the semantics should be clear:

class GenericDotNetLangInterpreter
{
    public:
       Results run(const Arguments& args);       

    protected:
       GenericDotNetLangInterpreter(const std::string &script);
};

class MyInterpreter : private GenericDotNetLangInterpreter
{
   public:
       MyInterpreter(const LanguageType l);
       Results run(const Arguments& args);       
}

Couple of questions:

  1. Has someone done this kind of thing before, and is there some code I can use as a reference point?

  2. what are some gotchas I need to be aware of going down this path?

Community
  • 1
  • 1
oompahloompah
  • 9,087
  • 19
  • 62
  • 90
  • Your question is missing words..."a .Net language (e.g. C#, VB.Net etc)" what exactly are you talking about here? You need to get a better idea of what your going to do and post that, what you have now is incomplete, the chances of sucess is slim. – Security Hound Aug 23 '11 at 16:04
  • @Ramhound: Hmmm, what would YOU define as a .Net language?. Most people would automatically infer (correctly), that I meant a CLI language. Ah well, not everyone is so bright, I will explixitly state that in my question to appease you. – oompahloompah Aug 23 '11 at 16:10
  • Found the answer [here][1] [1]: http://stackoverflow.com/questions/137933/what-is-the-best-scripting-language-to-embed-in-a-c-desktop-application – oompahloompah Aug 23 '11 at 18:10

2 Answers2

0

Not really an answer, but pointing out that C# and VB.Net aren't interpreted, but compiled to IL (similar to Java's Bytecode). In other words, your API name and signature would probably change. You would need to invoke the associated compiler and then execute the code.

There are .Net languages that can run interpreted on the DLR, but I'm not clear on calling that from a native language.

Tim Hoolihan
  • 12,316
  • 3
  • 41
  • 54
0

The limit between managed and unmanaged applications is thinner than it looks. Your C++ app can link with mscorelib (basic .NET support).

From there on, your C++ app can compile your text "script" to .NET byte code and execute it.

Whether it makes sense or is a good idea is left up to you.

Serge Wautier
  • 21,494
  • 13
  • 69
  • 110
  • Useful to know that. However, I would want more than just basic .Net support. I think I will edit the question to try to create the "script engine" in C# instead. – oompahloompah Aug 23 '11 at 17:57