News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Convert C/C++ structure to MASM format

Started by jj2007, June 09, 2022, 10:06:35 PM

Previous topic - Next topic

jj2007

Quote from: C3 on June 02, 2022, 05:59:32 PMI have been using MASM32 quite a long time. But now I'm doing only MASM and switching to MASM64 went fine. No problems at all. Using Visual Studio with a ASMDUDE and GitLab extensions.

But I found that there is something missing what is in legacy MASM32. Eg. there is no WSADATA structure for Winsock programming. It is in the MASM32.

Inspired by this post, I wrote a little application that can extract MASM structures from C/C++ headers. I hope it's self-explanatory. The Mode field refers to case & mode of Instr(); the default mode 0 means case-sensitive search, while 4 means full word (e.g. RECTL). Evidently, SIZE_P is DWORD for 32-bit and QWORD for 64-bit code.

Grateful for feedback about problems :thup:

Example (Winsock2.h):
typedef struct WSAData {
        WORD                    wVersion;
        WORD                    wHighVersion;
#ifdef _WIN64
        unsigned short          iMaxSockets;
        unsigned short          iMaxUdpDg;
        char FAR *              lpVendorInfo;
        char                    szDescription[WSADESCRIPTION_LEN+1];
        char                    szSystemStatus[WSASYS_STATUS_LEN+1];
#else
        char                    szDescription[WSADESCRIPTION_LEN+1];
        char                    szSystemStatus[WSASYS_STATUS_LEN+1];
        unsigned short          iMaxSockets;
        unsigned short          iMaxUdpDg;
        char FAR *              lpVendorInfo;
#endif
} WSADATA, FAR * LPWSADATA;

--->
WSADESCRIPTION_LEN = 256
WSASYS_STATUS_LEN = 128

WSADATA STRUCT
wVersion WORD ?
wHighVersion WORD ?
ifdef  _WIN64
   iMaxSockets WORD ?
   iMaxUdpDg WORD ?
   lpVendorInfo SIZE_P ?
   szDescription SBYTE WSADESCRIPTION_LEN+1 dup(?)
   szSystemStatus SBYTE WSASYS_STATUS_LEN+1 dup(?)
else
   szDescription SBYTE WSADESCRIPTION_LEN+1 dup(?)
   szSystemStatus SBYTE WSASYS_STATUS_LEN+1 dup(?)
   iMaxSockets WORD ?
   iMaxUdpDg WORD ?
   lpVendorInfo SIZE_P ?
endif
WSADATA ENDS

.DATA?
align 16
wsadata WSADATA <>


EDIT: Version 2 adds required equates, as e.g. WSADESCRIPTION_LEN   = 256 above

jj2007

New version attached: Tooltips for the buttons, and some refinements under the hood. Inter alia, you can now edit the C structure on the right, and you'll see the changes immediately in the MASM window on the left.

Enjoy :biggrin:

C3

Hey!

This is cool. I have to check tomorrow after a good sleep. I have noticed that there are other things that are missing too, but getting missing code in is very good. When I jumped in to MASM, I maked few of my own include-files, but noticed that it's too big to browse API's and make all include-files. Then I got serious and found good materials like this forum.

jj2007


quarantined

Quote from: jj2007 on June 10, 2022, 10:23:13 AM
Note that building the source attached above requires MasmBasic of 10 June 2022
Then why is this here in the Workshop? I also question why you use examples in the Campus that use MasmBasic? There are better ways to promote your MasmBasic than to try and peddle it to newcomers here. You have your own subforum dedicated exclusively to MasmBasic so just wondering why, oh why? Just my two cents.

jj2007

Quote from: quarantined on June 10, 2022, 11:14:26 AM
Quote from: jj2007 on June 10, 2022, 10:23:13 AM
Note that building the source attached above requires MasmBasic of 10 June 2022
Then why is this here in the Workshop? I also question why you use examples in the Campus that use MasmBasic? There are better ways to promote your MasmBasic than to try and peddle it to newcomers here. You have your own subforum dedicated exclusively to MasmBasic so just wondering why, oh why? Just my two cents.

I know one should not feed the troll, but I'll make an exception:

1. The Workshop is open to all coding questions. It was the traditional place to look for MasmBasic before the dedicated subforum was created. This thread is in the Workshop precisely because the converter can help experienced coders to do their work better.

2. A forum search helps to find out that the last posts dealing with MasmBasic in the Campus are ten years old, with the exception of one short xHelp for qEditor.exe thread. The xHelp application can be very useful for n00bs.

3. There is another extremely helpful forum function: go to a member's profile; in the lower left corner, click "Show posts" and have a look at what the member posted. In the 35 posts of quarantined, you will not find a single line of code.

Have a nice day, quarantined :thumbsup:

Gunther

Quote from: jj2007 on June 10, 2022, 05:34:31 PM
I know one should not feed the troll, but I'll make an exception:

Quarantined asked a simple and reasonable question. Can you answer without insulting and offending other forum members?
Who the troll is here can be seen by anyone who reads your unqualified reply.
You have to know the facts before you can distort them.