Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C .NET
Hi Smile | :)
 
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:
 

    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 :(
Posted 21-Nov-12 3:15am
Comments
Sergey Alexandrovich Kryukov at 21-Nov-12 14:06pm
   
My 5 for the question; more the for whole topic OP is going for; the question itself may seem somewhat naive, nevertheless, interesting enough... :-)
--SA
Alexandre Bencz at 21-Nov-12 17:28pm
   
Oh, thanks :)
[...... sensitive info removed ...... -- SA]
:)
Sergey Alexandrovich Kryukov at 21-Nov-12 17:43pm
   
You can contact me through my Web site known from my profile page, see "Contact me". If it does not work (I recently had trouble with hosting providers), please comment on any my post again.
 
We could talk. I reviewed your links. Your work may be very interesting, but without some description of your goals and appropriate architectural and development cycle overview, your code does not tell me much.
 
I've developed the whole successful code generation-based technology, metadata-driven. It was done before OMG Metadata Warehouse architecture was published, was way more lightweight and resembled OMG MEF (Meta-Object facility). However, later on, I concentrated on .NET-only (more exactly, CLI, also with Mono) and found it more productive to develop metadata-driven technology based on metadata coded manually in the form of .NET classes. Typically, these classes plays the role of (meta)metadata, meta-square-data (2nd degree of meta). This way, code generation in its traditional approach is excluded. You can use Reflection based on those .NET declaration and generate the whole UI, persistence (think Data Contract) and a lot more. I actually use this approach in applications, in the application fields where such degree of flexibility is really critical. Instead of traditional code generation, in certain parts, System.Reflection.Emit is used. The code is emitted, not generated. Sounds interesting?
 
Now I work, among other things, at alternative Data Contract persistence. In this field, persistence driven by just Reflection is pretty slow, so it can too slow for some applications, so I use System.Reflection.Emit. It it somewhat tedious work, but when the result is highly universal (and Data Contract technology is extremely universal, data-agnostic), it worth it.
 
--SA
Alexandre Bencz at 21-Nov-12 17:52pm
   
Oh, that's true :)
so, I have developed a intresting lib in C#, to generate an native EXE :)
https://github.com/bencz/CoffLib
Sergey Alexandrovich Kryukov at 21-Nov-12 18:26pm
   
Any documentation, even short?
--SA
Sergey Alexandrovich Kryukov at 21-Nov-12 17:46pm
   
Now, as to GNAT for .NET. This is very interesting.
 
I used regular Ada and Gnat for some systems, but not GNAT for .NET. Do you mean AdaCore product? But it looks like proprietary, not freeware or Open Source, right? Or do I miss something.
 
I tried Ada#, but it did not look like a complete working tool...
--SA
Alexandre Bencz at 21-Nov-12 17:55pm
   
I send one e-mail for you :)
Sergey Alexandrovich Kryukov at 21-Nov-12 18:28pm
   
Great. It works. Well, very interesting. Any additional info, like overview?
Anyway, let's keep in touch.
--SA
Sergey Alexandrovich Kryukov at 21-Nov-12 18:29pm
   
So, what about GNAT for .NET? Only commercial versions?
--SA
Alexandre Bencz at 21-Nov-12 18:49pm
   
No, only personal use :X
Sergey Alexandrovich Kryukov at 21-Nov-12 18:54pm
   
Really? Can I download and use it? Where? I looked through the Adacore site; only commercial product was mentioned...
(I do not mean commercial use; I mean commercial Ada product...)
--SA
Alexandre Bencz at 21-Nov-12 18:53pm
   
U recive my e-mail ?
Sergey Alexandrovich Kryukov at 21-Nov-12 18:55pm
   
Yes.
Please, don't show your e-mail address this openly anymore, otherwise you can be spammed really soon.
Do you speak/write Russian (I presume)? If so, you are welcome to use it.
--SA
Alexandre Bencz at 21-Nov-12 19:18pm
   
Найдено компилятор ? :)
Sergey Alexandrovich Kryukov at 21-Nov-12 20:29pm
   
OOPs... It looks like you don't... :-) I was confused with your Russian domain on one of e-mail addresses. How come?
No, this is not real Russian. The quality of automatic translations is the never-ending source of jokes... :-)
 
No, I don't know where to get GNAT for .NET... could you tell me?
--SA
Alexandre Bencz at 21-Nov-12 20:32pm
   
Ok :)
It's not real :)
i'm study russian, and, I don't have an whay to write in russian in my keyboard :)
btw... I send one e-mail for u whit one picture, where u can find the gnat.net :)
Sergey Alexandrovich Kryukov at 21-Nov-12 21:00pm
   
Russian language is very, very difficult. A Windows keyboard for Russian which is bundled with Window is too bad. Good thing can be found here:
http://winrus.com/index_en.htm
You should better use "phonetic" keyboard, so you can easily type Russian based on location of Latin characters. Also, the site has (the only) good on-screen virtual keyboard, HTML+JavaScript.
Also, there is a new Microsoft product, keyboard layout manager... where is that? I can find it. Main thing: don't use the default layout -- it's must die.
 
--SA
Sergey Alexandrovich Kryukov at 21-Nov-12 21:05pm
   
Thank you for the GNAT link. I'll take a look soon.
I do Skype, will send your a message later, or just find me...
I'm at (UTC-05:00) Eastern Time (Massachusetts, U.S.A.)
--SA
Alexandre Bencz at 21-Nov-12 21:09pm
   
Oh, ok :)
so, The language of my country is 100 times more complicated than the Russian :)
Sergey Alexandrovich Kryukov at 21-Nov-12 21:22pm
   
Do you mean Portuguese? More complicated? I cannot believe that. However, I am unable to argue with you. You can write something in Russian but make mistakes in each clause which I can point out, but I cannot write anything in Portuguese at all -- what a shame! :-)
 
By the way, this is very funny: Here in U.S. we has several cases when people thought we are not Russian, by hearing the speech, but with only one culture it was the case when people thought we talked the same language as they did -- it was with Brazilians. By some reason, from distance, they felt like our Russian speech sounds like Brazilian Portuguese. Most typically, that was some people of service, such as waiters at a restaurant. They would come to us and speak to us in Portuguese right away. "Sorry, I don't understand your language" -- surprise. "Where you are from?"... At the same time, I never confused Brazilians with Russians and did not see such a big similarity in speech... This is kind of wonderful...
 
--SA
Alexandre Bencz at 21-Nov-12 21:27pm
   
What do leaves Brazilian Portuguese complicated is that our language is very romantic, there are many sounds, words are EXTREMELY BASICALLY divided by male and female, and there are words that are both at the same time :)
btw, I said something very wrong in saying that the Portuguese is different from Russian, because there are many words that are almost the same :)
All languages ​​are complex, until us study.
Sergey Alexandrovich Kryukov at 21-Nov-12 22:25pm
   
Still, complexity is different. You might think that in Russian there are no such complexities you just described, just because you did not face them. Moreover, there are many subtleties many Russians don't pay attention (actually, many Russians make awful mistakes in Russian, oral and written). I often ask Russian-speaking people, for example, "Did you pay attention that there is a special "female Russian"?", and most will answer "no". But then I'll tell them some phrases, asking, "would you say things in this way?" and only them they can see it.
 
There is a famous Russian movies "Mistake of the Resident" and "Destiny of Resident". And the Russian double agent teaches a spy to get to Russia and to the mission. That person pronounces perfectly and know widest Russian word repertoire but eventually says: "This is -- not understandable what". Actually, the grammar is nearly perfect. And the Russian agents notes: "In Russian, you should say "understand" from first face in singular future form ("не поймешь что") instead". This is the usage. Present indefinite should be expressed in future perfect. It's funny that traditional Russian grammar teaches that there are only 3 tenses, but this is not true -- "theory" ignores it. In contrast, English grammar teaches 12 tenses (or so), but they are just simple combinations. English-speaking people often say that there are irregular words, etc., but in Russian more then 50% of word forms are "irregular". :-)
 
I think, for a foreigner, it's almost impossible to learn Russian just to the level to avoid mistakes, forget about perfection...
 
The attitudes related to language are also very different. English-speaking people, especially Americans, will ignore many mistakes in language; and they will easily understand very mangled English. Brazilians, in Russian culture, are pictured as overly "romantic", sensitive or, more exactly, sentimental (I'm not saying this is true, just don't know; the opinion is mostly inferred from soap operas :-), but Russians, seeing your Russian, would tend to lough at it (even though, for example, they speak some country dialect, and your Russian is perfect literature language -- then they would lough because the language is too much like "in a book").
 
Very many Russians generally tries to make fun of everything and would not mind laughing at them; and other people often perceive it in a wrong way, even get it as an offense, seeing something evil where this is nothing negative at all... Different language makes people think and feel somewhat differently...
 
Look, I'm getting tired -- will talk later.
 
Cheers,
--SA
Alexandre Bencz at 21-Nov-12 21:11pm
   
I'Il whait the e-mail whit your skype :)
Sergey Alexandrovich Kryukov at 21-Nov-12 21:24pm
   
OK. In the meanwhile, you can send me your Skype ID through my site. I'll add you account and eventually see when you are online. I don't have Skype at work, but it should not be a problem, will install it later.
--SA
Alexandre Bencz at 21-Nov-12 21:28pm
   
Ok :)
I already sent the email
Sergey Alexandrovich Kryukov at 21-Nov-12 21:58pm
   
Got it. OK, I'll get to Skype later today or tomorrow and add your account.
Best wishes,
--SA
Alexandre Bencz at 21-Nov-12 22:03pm
   
Oh, OK :)
And, I will go to sleep, now is 01:02am :)
Sergey Alexandrovich Kryukov at 21-Nov-12 22:35pm
   
Good night. Will talk later...
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You cannot use System::Reflection to dig into unmanaged code by one simple reason: it does not have metadata used by Reflection.
 
If you understand how .NET works, you can see that the compiler (and the IDE) can "see" all the metadata of referenced assemblies and can ensure correct linkage of all the "external" types and their members during compilation. In C++, there is no such things at all. Legacy languages was created oriented to single-module programming, and modular programming was introduced based on archaic bad dirty #include (header files) and object files.
 
In fact, many programming systems working with unmanaged platforms, had metadata similar to the .NET metadata many years ago: Ada, Turbo Pascal, Object Pascal, Delphi, Modula, and a lot more. The major difference with .NET is: that old metadata was totally implementation-depended (Ada programming systems by different manufacturers had incompatible metadata structures and formats), and, importantly, metadata was not included in executable modules, as it is done with NET assemblies. The metadata of those systems worked pretty much line in .NET, but it had to be supplied separately, as with C++ object files or libraries; that metadata could be considered as extension of object-file system, not executable modules.
 
If you look thoroughly at C++, C++/CLI mixed mode (managed + unmanaged) development and even at P/Invoke, you can easily figure out that metadata information is passed either through actual source code (mixed-mode case) or "manually", by writing method signatures of method based on some preexisting knowledge. Why do you think? Because the lack of metadata. And this is the exact reason why it's not possible to make Reflection capable of "seeing" the declaration of unmanaged code.
 
—SA
  Permalink  
v7
Comments
Alexandre Bencz at 21-Nov-12 13:37pm
   
Oh, Thanks Sergey Alexandrovich Kryukov ( beautiful name ) :)
btw... https://gist.github.com/4116247
look that link, in this link, I have puted the SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE OF SAMPLE.... of my experimental language :)
So, for example, If i want to use the MessageBox ( of .net ) I need to know the return type, so, to get this information, to use in codegen, I need to get from mscorlib.dll ( system.windows.forms .... btw), and, when I see the Ada .net, I see one project inside the ada code, to generate an "header" with .net methods information ( see my question...: http://stackoverflow.com/questions/8141727/using-net-commands-in-ada )
 
So, one guy in StackOverFlow, recomended to use the: Shared Source Common Language Infrastructure 2.0
And see the file: csharp/sscomp/import.cpp :)
So, let's go to study more and more :)
SO, THANKS FOR YOUR "SOLUTION", very very intresting :) and good :)
Thanks a lot :)
Sergey Alexandrovich Kryukov at 21-Nov-12 13:47pm
   
You are very welcome.
Thank you for accepting the answer (could not be a solution, but does not have to be), and for the links. I'll take a look. If I have interesting notes, I'll write you my feedback, let me see.
 
Good luck, call again.
--SA
Sergey Alexandrovich Kryukov at 22-Nov-12 11:43am
   
OK, now I can answer your question in StackOverflow:
http://stackoverflow.com/questions/8141727/using-net-commands-in-ada
 
Please do the following:
1) ask a new question at CodeProject;
2) notify me by adding your comment to this comment;
3) in this comment, give me a link to your new question.
 
OK?
 
(Quality of .NET binding is really frustrating, but I managed to put .NET Ada 2012 application to work. For a comprehensive work-around might be needed: an application to automate the build of data binding packages (the company effort is ridiculous); the projects can be done custom to add this step. Additional problem is: interference of the .NET framework installation of versions above 2.0 with the v.2.0, required for the GNAT bindings. For now, I resolved it manually.)
 
--SA
Alexandre Bencz at 22-Nov-12 11:54am
   
Oh, ok :)
so, i'm only on Skype :)
 
http://www.codeproject.com/Questions/497711/Usingplus-netpluscommandsplusinplusAda

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Schatak 400
1 OriginalGriff 355
2 Sergey Alexandrovich Kryukov 144
3 _Amy 115
4 Rob Philpott 100
0 OriginalGriff 7,097
1 Sergey Alexandrovich Kryukov 5,623
2 Maciej Los 3,504
3 Peter Leow 3,373
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100