Author Topic: Different size of structure needed by masm and c++  (Read 7308 times)

TouEnMasm

  • Member
  • *****
  • Posts: 1290
    • EditMasm
Different size of structure needed by masm and c++
« on: October 13, 2012, 04:11:49 AM »

I have used the TOOLINFO structure in masm and VC++ on XP3
Surprise,masm need a size of 2ch and vc++ 30h (+4 void *lpReserved)
The c++ and masm code are attached
Any idea on how it is possible ?

Quote
//################################################################
int AddTooltip (HWND Hwnd,HWND Hcontrole,LPSTR psztext)
{
      TOOLINFO toolInfo;
      DWORD retour;
      ZeroMemory(&toolInfo,sizeof (toolInfo));
        toolInfo.cbSize = sizeof (toolInfo);//30h masm 2ch
       toolInfo.hwnd = Hwnd;
       toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
       toolInfo.uId = (UINT_PTR)Hcontrole;
       toolInfo.lpszText = psztext;
      // problem size is not the same with masm
      int taille =sizeof (toolInfo.lpszText); //4 XP3 NOT EXIST
      taille = _WIN32_WINNT;//601h
      //-------------------------------------
      //#if (_WIN32_WINNT >= 0x0501) //need GT > 501h masm XP3 = 501
      //    void *lpReserved;   // +++ Not need in XP3 for masm
      //#endif
      //} TTTOOLINFOA, NEAR *PTOOLINFOA, *LPTTTOOLINFOA;

      //-------------------------------
       retour = SendMessage(hToolTip, TTM_ADDTOOL, 0,(LPARAM)(LPTOOLINFO) &toolInfo)   ;
   return retour;       
}
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 10446
  • Assembler is fun ;-)
    • MasmBasic
Re: Different size of structure needed by masm and c++
« Reply #1 on: October 13, 2012, 04:26:44 AM »
Any idea on how it is possible ?

Because Windows couldn't care less how big the struct is. This works just fine:

   MbTIS   TOOLINFO <?>
   dd 100 dup(?)
   ...
         m2m [esi.TOOLINFO.cbSize], sizeof TOOLINFO+400

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Different size of structure needed by masm and c++
« Reply #2 on: October 13, 2012, 05:56:17 AM »
_WIN32_WINNT is likely to be defined under VC, and a manifest created

Quote
For _WIN32_WINNT  > 0x0501, you must set 'cbSize' to TTTOOLINFOA_V2_SIZE (instead of
sizeof(TOOLTIPINFO)) or include the appropriate version of Common Controls in the manifest.
Otherwise the tooltip won't be displayed.

jj2007

  • Member
  • *****
  • Posts: 10446
  • Assembler is fun ;-)
    • MasmBasic
Re: Different size of structure needed by masm and c++
« Reply #3 on: October 13, 2012, 09:45:55 AM »
The tooltips do display with the above extra 400 bytes. Windows might have problems with less bytes, but not with more...

For masochists, here is the definition of TTTOOLINFOA_V2_SIZE from C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\CommCtrl.h:

#ifndef CCSIZEOF_STRUCT
#define CCSIZEOF_STRUCT(structname, member)  (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
#endif


#define TTTOOLINFOA_V1_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lpszText)
#define TTTOOLINFOW_V1_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lpszText)
#define TTTOOLINFOA_V2_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lParam)
#define TTTOOLINFOW_V2_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lParam)
#define TTTOOLINFOA_V3_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lpReserved)
#define TTTOOLINFOW_V3_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lpReserved)

typedef struct tagTOOLINFOA {
    UINT cbSize;
    UINT uFlags;
    HWND hwnd;
    UINT_PTR uId;
    RECT rect;
    HINSTANCE hinst;
    LPSTR lpszText;
#if (_WIN32_IE >= 0x0300)
    LPARAM lParam;
#endif
#if (_WIN32_WINNT >= 0x0501)
    void *lpReserved;
#endif
} TTTOOLINFOA, NEAR *PTOOLINFOA, *LPTTTOOLINFOA;

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: Different size of structure needed by masm and c++
« Reply #4 on: October 13, 2012, 09:59:27 AM »
Jochen,

that's awful. I luke especially that:

#ifndef CCSIZEOF_STRUCT
#define CCSIZEOF_STRUCT(structname, member)  (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
#endif

 :icon13:

Gunther
Get your facts first, and then you can distort them.

TouEnMasm

  • Member
  • *****
  • Posts: 1290
    • EditMasm
Re: Different size of structure needed by masm and c++
« Reply #5 on: October 13, 2012, 11:50:52 PM »

This macro can be usefull:
Quote
CCSIZEOF_STRUCT MACRO structname:REQ,member:REQ
   Local structsize
   chaine CATSTR <structname>,<.>,<member>
    structsize equ offset chaine - offset structname + sizeof chaine
   EXITM<structsize>
ENDM
Add it to the commctrl.sdk after the line:
IFNDEF CCSIZEOF_STRUCT
And you will have all the TTTOOLINFOA_V(N)_SIZE  defined and more.
usage:
mov eax,CCSIZEOF_STRUCT(TTTOOLINFOA,lParam)

Quote
For _WIN32_WINNT  > 0x0501, you must set 'cbSize' to TTTOOLINFOA_V2_SIZE (instead of
sizeof(TOOLTIPINFO)) or include the appropriate version of Common Controls in the manifest.
Otherwise the tooltip won't be displayed.
Is it possible to have a sample who show a working and not working code ?.





Fa is a musical note to play with CL