Parse.h header files in C # data structures at runtime

I am trying to write a C # library to manage my C / C ++ header files. I want to be able to read and analyze the header file and manipulate function prototypes and data structures in C #. I try to avoid writing C Parser due to all code errors caused by #ifdefs and the like.

I tried to play with EnvDTE, but could not find decent documentation. Any ideas how I can do this?

Edit - Thanks for the answers ... Here are some details about my project: I am writing a ptrace-like tool for Windows using the debug APIs that allow me to track my already compiled binaries and see which Windows API is being called, I also want to see which parameter is specified in each call and what values ​​are returned, so I need to know the definition of the API. I also want to know what is needed for my own libraries (hence the header analysis approach). I thought of three solutions: * Parse file headers * Parse PDB files (I wrote a prototype using the DIA SDK, but unfortunately the PDB symbols only contain general information about the API, not real prototypes with parameters and return values) * Scan through MSDN online library (automatically or manually)

Is there a better way to get names and types for windows APIs and my libraries at runtime in C #?

+3
source share
2 answers

Parsing C (even "only" headers) is difficult; the language is more complex than people remember, and then there is a preprocessor and, finally, the problem is something to do with parsing. C ++ includes essentially all of C, but with C ++ 11, the problem here is even worse.

People can often crack the 98% solution for a limited set of inputs, often with regular expressions in Perl or some other hacker hacker. If this works for you, then good. Typically, 2% causes the hacked parser to suffocate or give the wrong answer, and then you can debug the result and manually crack the yield of 98%.

, , , , , ( C ++ ). . Microsoft.h . , , OP . , C / ++. 98% - ; typedefs , , . "" FOO X; , X FOO... oops, ? .

GCCXML , ... GCC C. Microsoft , , GCCXML .

- DMS Software Reengineering Toolkit C ; ++ front end (, , C ++ - ). C ( MS, GCC ), / , AST ( ).

, , . , # (, #), DMS .net.

+4

, .

(#define) , .., .

  • ##

//header
#define mystructconstant "bla","bla"

// in using .c
char test[10][2] ={mystructconstant};

,

..

, ( ) (, MS SDK).

, . - .

, , SWIG.

0

All Articles