[C++/CLI] Determine struct layout from header file - reflection?

G

Guest

Hi guys,

I'm trying to figure out a way to do reflection on structs which are in a
legacy c++ header file. Basically I want to write a C++/CLI program that lets
me edit the binary data in the structs, but there are many of these structs
so it has to be automated. Also I do not want to have to modify the legacy
struct definitions.

Firstly if I simply include the .h file then none of the structs appear in
the assembly. So I guess first of all I must do a hack where an instance of
each of the structs in created so that it appears in the assembly.

Unfortunately when I look using reflector I see that the assembly still
dosnt really 'know' anything about these structs. The offsets for the fields
are basically hard coded into the accessing code. There is no struct with
named fields accessble for reflection in the assembly.

Can anyone give me some ideas on how to accomplish what im trying to do?
(find out layout of legacy c++ structs without modifying the source file).

Thanks
 
M

Marcus Heege

C++/CLI is not able to do what you want.

C++/CLI does not create metadata for native classes and structs (with one
exception that is not relevant here.)
The only option I see is parsing the .h file to get the metadata for the
native types.

Marcus Heege
 
G

Guest

What is the exception?

Is the C++ Code DOM going to help me much in this case? It wouldnt
understand much about the struct layouts would it?

I remember there is an API for examining some of the output files of the cpp
compiler that contains all the struct layout info in it, but I cannot
remember what is it called. Its quite old I think.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top