473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Nov 17 '05 #1
2 2500
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

"Jack Ukleja" <Ja********@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
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

Nov 17 '05 #2
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.

"Marcus Heege" wrote:
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

"Jack Ukleja" <Ja********@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
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


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
Hi, Is there any good links for datatype interop? I need to pass some structure pointers into an unmanaged method and return char* etc but having some problems in my C++/CLI proxy class. I...
3
by: GrkEngineer | last post by:
I recently had to use someone's struct from a native app to receive data over Udp. The struct has a array member which looked like this: struct sensorHdr{ char sName; }; When I tried to make...
2
by: None | last post by:
Hello To get an understanding of UI threads in C++/CLI, I attempted to duplicate the following C# example: ...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
81
by: Don Kim | last post by:
I've been looking for a new IT position, and so far, the majority of work with respect to the Windows platform is C#/.Net, with some vb.net requests every so often. Even many of the C++/MFC/ATL...
12
by: Edward Diener | last post by:
Given value class X { public: // Not allowed: X():i(100000),s(10000) { } // Allowed void InitializeDefaults() { i = 100000; s = 10000; } private: int i;
12
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
9
by: AM | last post by:
Hi, I have a C++ Dll that has a function that is being exported as shown below extern "C" __declspec(dllexport) validationResult __stdcall _validateData(double dataToMat, int time); A...
6
by: MACKTEK | last post by:
Intro: I have recently started programming in C++/CLI. I have done a lot of research on the net trying to locate an answer to this problem, but there seems to be a lack of Tutorials and books on...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.