Reflection in c++

Discussion in 'C++' started by SaswatPadhi, May 15, 2009.

  1. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Can someone guide me on achieving Reflection in C++ ?

    It can be done easily in C# or Java, as they have built-in reflection facilities, but how do I do it in C++. I googled a lot but didn't find anything significant. :(
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    It is possible to have reflection in C++ but then it should be done manually and not automatically.

    I have done this for my last job but before I explain what I did I would explain why it could not be done.

    When you compile Java / C# programs and convert them into binaries they are not actual binaries which can be run directly on the CPU containing language understood by the CPU but they contain instruction which can be understood by the intermediate language ( JVM or anything you call it )

    Now when you compile the C++ code you actually generate Assembly language code which means it does not have the definition for function classes but actually all being converted.

    This is the main reason why reverse engineering is also not possible to the full in C++ but its very much an option in Java and C#.

    Now the question comes how to do reflection in C++.

    What I saw is when you create dll in C++ you can use the dll viewer to check out the functions defined in dll and so it met me thought that some Meta Data about the dlls are contained within the Dll.

    So what I did is for certain set of dll I had same function which helped me get lot of things out of that dll.

    Say I have a function
    GetMetaData

    And then it lists me all the things that I need outside of that dll and that way you can try out but there are some limitations to it as well.

    Say you want a class object to be used in the calling function from the dll and for that at times you may need the .h file in both application.
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yes really nice one and quite inline of what I have suggested.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice