title: Accessing a C++ non-member function from C# via reflection
body: <p>I need to gain some run-time information about a C++ program, which is kinda difficult due to C++ not offering some sophisticated reflection mechanism. Now, my approach is to compile the C++ code using /clr and to reflect over the resulting assembly from C# (simply because I like that language more than C++).</p>
  
  <p>While this is all turning out more or less fine, I'm now stuck at a point where I need to actually run the program by calling its main method. Which is kind of frustrating considering how far I got already...</p>
  
  <p>This is the C++ program in question:</p>
  
  <pre><code>#include "systemc.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  // Hello_world is module name
  SC_MODULE (HelloWorld) {
      SC_CTOR (HelloWorld) {
          // Nothing in constructor 
      }
      void HelloWorld::say_hello() {
          //Print "Hello World" to the console.
          cout &lt;&lt; "Hello World.\n";
      }
  };
  
  //sc_main in top level function like in C++ main
  int sc_main(int argc, char* argv[]) {
    HelloWorld hello("HELLO");
    hello.say_hello();
    string input = "";
    getline(cin, input);
    return(0);
  }
  </code></pre>
  
  <p>Nothing fancy, really...</p>
  
  <p>This is the C# method used to inspect the resulting assembly:</p>
  
  <pre><code>System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom(filename);
  
  System.Console.WriteLine(filename + " is an assembly and has been properly loaded.");
  
  Type[] hello = ass.GetTypes().Where(type =&gt; type.Name.ToLower().Contains("hello")).ToArray();
  Type[] main = ass.GetTypes().Where(type =&gt; type.Name.ToLower().Contains("main")).ToArray();
  </code></pre>
  
  <p>Now, while the hello Type-array contains the HelloWorld class (or at least I assume that it is that class), the main var contains three types, all of which deal with doMAINs (ie have nothing to do with the sc_main method I'm looking for). I assume that it has something to do with it not being public, but declaring it a static public member function of the HelloWorld class doesn't work either since the function is expected to be a non-member function to be found. Or am I just overlooking something terribly stupid?</p>