Today is the time to show what's under the hood in the new h2incX project.
It took me some time to analyse the Japheth’s original code. It became clear to me that this project was in a phase where code was still being tested and some other routines were not finished yet.
I decided not to modify the core of how the program was originally designed, but changed the code where necessary to add some necessary new features, such as parsing of annotations and some bug fixes.
Purpose:
This tool is a Win32 console application, whose purpose is to convert C header files to MASM-style include files. A private profile file is used to fine-tune the include files to be created.
Huge C header sets can be converted in one run, for example the Win32 headers in the "Windows Kits" or "PSDK".
Prototypes can be written so that the include file is suitable for dynamic linking to a DLL, using the IAT entries, as well as for static linking to a library.
Optionally, a .DEF file can be written to generate an import library.
Features and limitations
h2incX is very reliable, but it is not perfect. Without a full-fledged C-precompiler/compiler, manual intervention will always be required.
It should be noted that some C header file declarations simply cannot be translated into ASM. For example, there are no things like inline functions in ASM for example.
On some situations h2incx has to "count" braces. This can interfere with “#if“ pre-processor commands, because h2incX cannot evaluate expressions in these commands. As a result, h2incX can become confused and produces incorrect code.
h2incX has some limited knowledge about C++, but its original purpose was to convert C headers. So some C++ specific keywords can confuse h2incX. This also applies to templates.
"far" and "near" qualifiers are skipped, so this tool does not work for 16bit includes.
The current MASM / UASM implementation treats the conditional compile statement "if" differently than the C equivalent “#if”. Therefore, some problems may occur when symbols are undefined.
Result
I took the latest Kit for Win10 and translated all the .h files following the inclusion tree, starting with Windows.h. Unfortunately, the resulting .zip file containing the generated .inc files exceeds the allowed quota of the forum, so I am forced to put the .zip file on an alternative server.
Final notes
The source code is attached to this post. To avoid confusion, I have restarted the h2incX versioning with "B.01.00".
The original code used some pseudo-OO constructs, which I replaced with ObjAsm32 code. This change allowed much better handling of internal lists. The output of its contents is copied to .lst files for better verification of results.
Memory management has also been streamlined, but the core idea of how the information is stored remains the same.
I checked the result with some x64 projects and quickly found that more .h files needed a translation, for example CommCtrl.h. Based on this experience, if someone notices missing files, please report it here, so it can be added to the distribution.
Regards, Biterider