News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

h2inc+

Started by Biterider, March 29, 2024, 10:45:35 PM

Previous topic - Next topic

Biterider

Hi sinsi
Thank you for your thoughts. 
In the beginning I had the same ideas, but based on the experience I gained with this project, I realised that a translator has to work a bit differently. This is because you don't have a preprocessor that 'simply' inserts or discards part of the code. The translator has to go through all possible PP code paths and arrange the code in a way that a MASM-compatible assembler can understand. One of the challenges we have is that the HL directives such as if, else, endif cannot be placed as flexibly as in C.

Nevertheless, it might be interesting to explore your idea further. Unfortunately, I don't know of any open source C compiler code that could be modified for our purposes.

The results of the current h2incX engine are actually very good (you can have a look here https://github.com/ObjAsm/ObjAsm-C.2/tree/master/Code/Inc/Windows). I have been using it for a long time without any problems in 32 and 64 bit.

The reason for a reworked engine is the amount of work needed to make small corrections afterwards. These are exactly the cases I wanted to show with some examples in the previous post.


Regards, Biterider

sinsi

Just a thought out of left field, but have you seen the Magic Number DataBase?
Parsing the Windows headers for constants, maybe it could be extended?

Biterider

Hi Sinsi
I solved the record problem and some others, but at the same time I introduced some regressions.
Maybe this weekend I can post a very first beta. The application is designed to selectively output protos, constants, structures/unions, etc. using some CL-switches. 
The implementation of this selectivity dfeature is not fully implemented yet, as I'm concentrating on the rendering atm.

Regards, Biterider


Biterider

Hi
I'm finishing the core functionality and leaving the "extern" declarations for the end. In the current state, the application can render most of the header files but has problems with this code:
extern "C" {
typedef BOOL (CALLBACK * ImageAbort)(VOID *);
typedef ImageAbort DrawImageAbort;
typedef ImageAbort GetThumbnailImageAbort;
}

Can anyone fluent in C explain what these lines do and what the MASM equivalent would be?

Biterider

TimoVJL

first declare callback function and next two with predefined names of them.
May the source be with you

Biterider

Hi Timo
Thanks for the quick replay  :thumbsup:
I'm a bit confused about the "typedef".
As far as I understand it, the first line defines a typedef to a proto and the 2 following lines uses this type to define 2 extern C functions.
Do you know how to translate it to MASM?

Biterider

fearless

At a guess, maybe could be written in masm something like this:

ImageAbort_Callback_Proto  TYPEDEF PROTO C VoidPtrParam:DWORD
ImageAbort_Callback        TYPEDEF PTR ImageAbort_Callback_Proto

.DATA

DrawImageAbort              ImageAbort_Callback 0
GetThumbnailImageAbort      ImageAbort_Callback 0

The DrawImageAbort and GetThumbnailImageAbort values can be assigned at runtime, before they are used and then can be used in Invoke's like:

Invoke GetThumbnailImageAbort, Addr hImageAbort
But its just a guess based on the code

Biterider

Hi fearless
Thanks for your hints.
I came now to the following translation

ImageAbort_Proto typedef proto C :ptr
ImageAbort typedef ptr ImageAbort_Proto
DrawImageAbort typedef ImageAbort
GetThumbnailImageAbort typedef ImageAbort

in the same header file I can now use the following translation
GdipGetImageThumbnail_ proto WIN_STD_CALL_CONV :ptr GpImage, :UINT, :UINT, :ptr ptr GpImage, :GetThumbnailImageAbort, :ptr VOIDwhich works fine.

In my opinion, the extern directive in C for a typedef is not relevant for masm.

Biterider

Biterider

#53
Hi
I have solved most of the problems mentioned above and now it is time for a very first beta release. The attached binary is compiled for debugging (pdb is provided to track a bug). The application options can now be placed in an environment variable or file using the "@" command line option, like in other modern tools.

h2inc+.exe -@".\h2inc+_Options.txt"
I provide all the list files where the collected knowledge is stored.
So far I managed to compile the latest set of header files "um_10.0.22621.0" without errors, but tests with other APIs are welcome to strengthen the renderer engine.

In terms of performance, the application rendered 192 header files in less than 1.9 seconds on my machine, which is very good.
The translated set of .inc files can be seen here
https://github.com/ObjAsm/ObjAsm-C.2/tree/master/Projects/X/h2inc%2B/inc

I did not enable exception handling to better catch crashes. It will be enabled in the final version.

Regards Biterider

jj2007

Compliments, Biterider - right now I am too busy to test it, but I surely will :thumbsup:

Thank you

Biterider

Hi
Some improvements in beta 2
  • Comments option works now
  • Untyped parameters and structure members options works now
  • Console output enhanced
  • Def-file output enabled
  • Selective output implemented over the complete code

Update in the first post. All planned features have been implemented in this version.

Regards, Biterider


sudoku

Quote from: Biterider on May 21, 2024, 04:22:23 AMUpdate in the first post. All planned features have been implemented in this version.
Hi, maybe it was by accident but the attachments appear to be posted in #53 above not in the first post.
Do I need ObjAsm installed to run it? (I didn't realize I was in the ObjAsm board until I tried the program) :smiley:
So it appears it is not a stand-alone program.
:azn:

Biterider

Hi sudoku
Thanks for your comments. The updated files are indeed in post #53.  :thumbsup:

The translator is a standalone command line application that only needs the knowledge-lists and the ini-file. No other files or frameworks are needed, but to build the application you will need ObjAsm.

Tomorrow I will write a post describing how to use h2inc+ in detail. For now, you can simply start the application from the command line and a short description will be displayed.

Regards, Biterider

sudoku

Quote from: Biterider on May 21, 2024, 06:24:10 AMThe translator is a standalone command line application that only needs the knowledge-lists and the ini-file. No other files or frameworks are needed...
But when running h2inc+ I get...

Looks like a dependency. That is why I asked if it was stand-alone or not.
:azn:

Biterider

Hi sudoku
You are right. ResGuard is a resource leak detection tool that requires another tool called DebugCenter to visualise the results. 
To avoid complications for those who don't have ObjAsm installed, I disabled ResGuard and recompiled the project. 
The new binary and pdb can be found in post #53  :biggrin:

Biterider