Click here to Skip to main content
15,891,874 members

Get managed informations using unmanaged code

Alexandre Bencz asked:

Open original thread
Hi :)

I'm developing a simple compiler for .Net, in C++, but am having problems with my include system, therefore not seem to find a way to recognize what kind of method I'm calling from dll if it is void , string, int...
so, my include system call the .net dll call

@include System
@include System:Windows:Forms


when will generate the code, need to know, what kind of method...
I wonder if anyone knows a way to get the type of methods, without using tools .net

One way I thought of using it: Create an application in C# or another .net language to generate a TXT, and this txt, contain the name of the methods and their proper type, and at compile time, I carry this txt and caught at compile time the type of method

But, I whant to know, if have an another way.

Thanks.
Alexandre

>----------------------------------------------

About this program that I talked is that:


C++
using namespace System;
using namespace System::IO;
using namespace System::Reflection;

ref class Reflector
{
public:
    void LoadAndReflect(String^ assemblyFileName)
    {
        Assembly^ assembly = Assembly::Load(assemblyFileName);
        array<Type^>^ types = assembly->GetTypes();
        StreamWriter^ sw = gcnew StreamWriter("mscorlib.txt");

        for each(Type^ t in types)
        {
            array<MethodInfo^>^ methods = t->GetMethods();

            for each(MethodInfo^ method in methods)
            {
                String^ base = method->ReturnType->ToString();
                array<String^>^ auxBase = base->Split('.');
                if(auxBase->Length > 1)
                    sw->WriteLine(String::Format("{0} <::> {1}", auxBase[1], method->Name));
                else
                    sw->WriteLine(String::Format("{0} <::> {1}", auxBase[0], method->Name));
            }
        }
        sw->Close();
    }
};

int main(array<System::String ^> ^args)
{
    Reflector^ ref = gcnew Reflector();

    Console::WriteLine("Reflection on {0}", "mscorlib.dll");
    ref->LoadAndReflect("mscorlib.dll");
    return 0;
}


And, in compiler time, I open that txt and I get the method type
....


>---------------------------------- Edit 12:14 ( BRT )

I know ( now ) about the IMetaDataAssemblyImport, but, I don't know, how to get the informations usint that class :(
Tags: C++, C, .NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900