NO

Author Topic: struct info  (Read 435 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1582
struct info
« on: August 26, 2016, 11:06:04 AM »
In masm32 forum this topic inspirate to do this test:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#include <ImageHlp.h>
#include <stddef.h>
// http://www.catb.org/esr/structure-packing/
// http://stackoverflow.com/questions/1208954/c-struct-grabbing-data-by-offset
#ifndef offsetof
#define offsetof(ty,m)  ((size_t)&(((ty*)0)->m))
#endif
#define GET_FIELD_OFFSET(type, field)    ((size_t)&(((type *)0)->field))
#define GET_FIELD_SIZE(type, field)      (sizeof(((type *)0)->field))

#define PRINTSIZE(x)  printf("\n%-16s %d %Xh bytes\n",#x,sizeof(x),sizeof(x));
#define PRINTOFSSIZE(type,field) printf("%-16s +%Xh %Xh\n",#field,(LONG)&(((type *)0)->field),sizeof(((type *)0)->field));
int main(void)
{
PRINTSIZE(PSINJECTDATA);
PRINTOFSSIZE(PSINJECTDATA,DataBytes);
PRINTOFSSIZE(PSINJECTDATA,InjectionPoint);
PRINTOFSSIZE(PSINJECTDATA,PageNumber);

PRINTSIZE(MCI_ANIM_WINDOW_PARMS);
PRINTOFSSIZE(MCI_ANIM_WINDOW_PARMS,dwCallback);
PRINTOFSSIZE(MCI_ANIM_WINDOW_PARMS,hWnd);
PRINTOFSSIZE(MCI_ANIM_WINDOW_PARMS,nCmdShow);
PRINTOFSSIZE(MCI_ANIM_WINDOW_PARMS,lpstrText);

PRINTSIZE(LOADED_IMAGE);
PRINTOFSSIZE(LOADED_IMAGE,ModuleName);
PRINTOFSSIZE(LOADED_IMAGE,hFile);
PRINTOFSSIZE(LOADED_IMAGE,MappedAddress);
PRINTOFSSIZE(LOADED_IMAGE,FileHeader);
PRINTOFSSIZE(LOADED_IMAGE,LastRvaSection);
PRINTOFSSIZE(LOADED_IMAGE,NumberOfSections);
PRINTOFSSIZE(LOADED_IMAGE,Sections);
PRINTOFSSIZE(LOADED_IMAGE,Characteristics);
PRINTOFSSIZE(LOADED_IMAGE,fSystemImage);
PRINTOFSSIZE(LOADED_IMAGE,fDOSImage);
PRINTOFSSIZE(LOADED_IMAGE,Version);
PRINTOFSSIZE(LOADED_IMAGE,Links);
PRINTOFSSIZE(LOADED_IMAGE,SizeOfImage);
return 0;
}
May the source be with you

Offline jj2007

  • Member
  • *
  • Posts: 445
Re: struct info
« Reply #1 on: August 28, 2016, 02:30:02 PM »
Hi Timo,

Thanks, that is interesting. In fact I had also on my (full) agenda to generate C code for all these structures, and let Pelles C (and MS VC, GCC) show what it really uses in 32-bit and 64-bit code. Haven't made progress, though - too many other things cooking 8)