The MASM Forum
Specialised Projects => Compiler Based Assembler => Assembler With Microsoft Visual C => Topic started by: TouEnMasm 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 ?
//################################################################
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;
}
-
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
-
_WIN32_WINNT is likely to be defined under VC, and a manifest created
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.
-
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;
-
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
-
This macro can be usefull:
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)
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 ?.