A series of macros is defined for packing data into, and extracting data from, variables of MPARAM and MRESULT data types. They are used in conjunction with the WinSendMsg and the other message functions, and also inside window and dialog procedures.
These macros always cast their arguments to the specified type, so values of any of the types specified for each macro can be passed without additional casting. NULL can be used to pass unused parameter data.
Macros for packing data into a MPARAM variable are shown below:
/* Used to pass any pointer type: */ #define MPFROMP(p) ((MPARAM)(VOID *)(p)) /* Used to pass a window handle: */ #define MPFROMHWND(hwnd) ((MPARAM)(HWND)(hwnd)) /* Used to pass a CHAR, UCHAR, or BYTE: */ #define MPFROMCHAR(ch) ((MPARAM)(USHORT)(ch)) /* Used to pass a LONG, ULONG, or BOOL: */ #define MPFROMLONG(l) ((MPARAM)(ULONG)(l)) /* Used to pass two SHORTs or USHORTs: */ #define MPFROM2SHORT(s1, s2) ((MPARAM)MAKELONG(s1, s2)) /* Used to pass a SHORT and 2 UCHARs: (WM_CHAR msg)*/ #define MPFROMSH2CH(s, uch1, uch2) ((MPARAM)MAKELONG(s, MAKESHORT(uch1, uch2)))
Macros for extracting data from a MPARAM variable are shown below:
/* Used to get any pointer type: */ #define PVOIDFROMMP(mp) ((VOID *)(mp)) /* Used to get a window handle: */ #define HWNDFROMMP(mp) ((HWND)(mp)) /* Used to get CHAR, UCHAR, or BYTE: */ #define CHAR1FROMMP(mp) ((UCHAR)(mp)) #define CHAR2FROMMP(mp) ((UCHAR)((ULONG)mp >> 8)) #define CHAR3FROMMP(mp) ((UCHAR)((ULONG)mp >> 16)) #define CHAR4FROMMP(mp) ((UCHAR)((ULONG)mp >> 24)) /* Used to get a LONG, ULONG, or BOOL: */ #define LONGFROMMP(mp) ((ULONG)(mp))
Macros for packing data into a MRESULT variable are shown below:
/* Used to pass any pointer type: */ #define MRFROMP(p) ((MRESULT)(VOID *)(p)) /* Used to pass a LONG, ULONG, or BOOL: */ #define MRFROMLONG(l) ((MRESULT)(ULONG)(l)) /* Used to pass two SHORTs or USHORTs: */ #define MRFROM2SHORT(s1, s2) ((MRESULT)MAKELONG(s1, s2))
Macros for extracting data from a MRESULT variable are shown below:
/* Used to get any pointer type: */ #define PVOIDFROMMR(mr) ((VOID *)(mr)) /* Used to get a LONG, ULONG, or BOOL: */ #define LONGFROMMR(mr) ((ULONG)(mr))
The following macros are for use with DDESTRUCT and DDEINIT structures are shown below:
/* Used to return a PSZ pointing to the DDE item name: */ #define DDES_PSZITEMNAME(pddes) \ (((PSZ)pddes) + ((PDDESTRUCT)pddes)->offszItemName) /* Used to return a PBYTE pointing to the DDE data: */ #define DDES_PABDATA(pddes) \ (((PBYTE)pddes) + ((PDDESTRUCT)pddes)->offabData) /* Used to convert a selector to a PDDESTRUCT: */ #define SELTOPDDES(sel) ((PDDESTRUCT)MAKEP(sel, 0)) /* Used to PDDESTRUCT to a selector for freeing / reallocating: */ #define PDDESTOSEL(pddes) (SELECTOROF(pddes)) /* Used to PDDEINIT to a selector for freeing: */ #define PDDEITOSEL(pddei) (SELECTOROF(pddei))