News:

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

Main Menu

Convert C/C++ structure to MASM format

Started by jj2007, July 16, 2023, 03:58:36 AM

Previous topic - Next topic

jj2007

A little tool that converts C/C++ structures to MASM syntax.

Take, for example, the structure posted by HSE here:

typedef struct _devicemode {
  TCHAR dmDeviceName[CCHDEVICENAME];
  WORD  dmSpecVersion;
  WORD  dmDriverVersion;
  WORD  dmSize;
  WORD  dmDriverExtra;
  DWORD dmFields;
  union {
    struct {
      short dmOrientation;
      short dmPaperSize;
      short dmPaperLength;
      short dmPaperWidth;
      short dmScale;
      short dmCopies;
      short dmDefaultSource;
      short dmPrintQuality;
    };
    struct {
      POINTL dmPosition;
      DWORD  dmDisplayOrientation;
      DWORD  dmDisplayFixedOutput;
    };
  };
  short dmColor;
  short dmDuplex;
  short dmYResolution;
  short dmTTOption;
  short dmCollate;
  TCHAR dmFormName[CCHFORMNAME];
  WORD  dmLogPixels;
  DWORD dmBitsPerPel;
  DWORD dmPelsWidth;
  DWORD dmPelsHeight;
  union {
    DWORD dmDisplayFlags;
    DWORD dmNup;
  };
  DWORD dmDisplayFrequency;
#if (WINVER >= 0x0400)
  DWORD dmICMMethod;
  DWORD dmICMIntent;
  DWORD dmMediaType;
  DWORD dmDitherType;
  DWORD dmReserved1;
  DWORD dmReserved2;
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
  DWORD dmPanningWidth;
  DWORD dmPanningHeight;
#endif
#endif
} DEVMODE, *PDEVMODE, *LPDEVMODE;


Copy the structure, then run the attached executable (there is also a slightly confused source :rolleyes:). The C+X (copy & exit) button copies the MASM structure to the clipboard.

The result:
DEVMODE STRUCT
dmDeviceName TCHAR CCHDEVICENAME dup(<>)
dmSpecVersion WORD ?
dmDriverVersion WORD ?
dmSize WORD ?
dmDriverExtra WORD ?
dmFields DWORD ?
UNION
???? struct <>
   dmOrientation SWORD ?
   dmPaperSize SWORD ?
   dmPaperLength SWORD ?
   dmPaperWidth SWORD ?
   dmScale SWORD ?
   dmCopies SWORD ?
   dmDefaultSource SWORD ?
   dmPrintQuality SWORD ?
ENDS
???? struct <>
dmPosition POINTL <>
dmDisplayOrientation DWORD ?
dmDisplayFixedOutput DWORD ?
DEVMODE ENDS

.DATA?
align 16
devmode DEVMODE <>


Not perfect, right. Most structures come out way better, but here we have a UNION with a non-named structure inside, so that's a pretty complex case ;-)

If you have only the name of the structure, then copy only the name, run the exe and hit Return. If you have Visual C installed, it will try to grab it from there. This may take several seconds.

guga

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com