HMG
64-bits Documentation
Since version HMG.3.3.0
(2014/04/24) HMG builds applications in 32 and 64 bits depending if the choice of compilation is
with build.bat or build64.bat respectively. When you
compile with the IDE select the
option “Build” in main menu.
Guidelines to make
compatible code with Win32/64-bits
#
PRG level: at high level is not
necessary any changes in your code, all Harbour
functions are portables to 64-bits.
#
C level: at low level
are necessary some changes in your code because HMG stores pointers in integer
numbers and the size of the pointers change with the architecture (32 or 64
bits), the other hand some functions of Windows that use HMG are not portables.
a) Values that can take 32 or 64 bits
HMG use many pointers and numbers type, and the size of the pointers and
some these data types are of 32 or 64 bits according to the architecture chosen
for compiling, for example:
-
All
Pointers: all GDI handles
(HANDLE, HBITMAP, HBRUSH, HCURSOR, HDC, HENHMETAFILE, HFONT, HGDIOBJ, HGLOBAL,
HICON, HINSTANCE, HKEY, HMENU, HMODULE, HPEN, HRGN, HWND, etc.), void*, int*, NULL, PVOID, LPVOID, PINT, LPINT, etc.
- Some data types such as: WPARAM, LPARAM, LRESULT, LONG_PTR,
LONG_INT, size_t, time_t,
etc.
b) Deprecated (obsolete) functions
Some API-functions are not portable to 64-bits and are considered
obsolete such as SetWindowLong, GetWindowLong, SetClassLong, GetClassLong, etc. If you need these functions in your
code, use the new equivalent functions (this list is not exhaustive): SetWindowLongPtr, GetWindowLongPtr, SetClassLongPtr, GetClassLongPtr, etc.
c) Create portable code
For
example, in 32-bits is created a high level version of the function SendMessage()
as:
HB_FUNC
( SENDMESSAGE )
{
HWND
hWnd
= (HWND) hb_parnl
(1);
UINT
Msg
= (UINT) hb_parnl
(2);
WPARAM wParam = (WPARAM) hb_parnl
(3);
LPARAM lParam = (LPARAM) hb_parnl
(4);
LRESULT ret;
ret = SendMessage (hWnd, Msg, wParam, lParam);
hb_retnl ((LONG)
ret);
}
But
this code is not portable to 64-bits because:
1) HWND,
WPARAM and LPARAM are 64-bit values and is assigned 32-bit values with hb_parnl()
2)is returned a LONG number (32-bit value)
whereas LRESULT is a 64-bit value
If
you desire write portable codes in
HMG you must write as:
HB_FUNC
( SENDMESSAGE )
{
HWND
hWnd
= (HWND) HMG_parnl
(1);
UINT
Msg
= (UINT) hb_parnl (2);
WPARAM wParam = (WPARAM) HMG_parnl
(3);
LPARAM lParam = (LPARAM) HMG_parnl
(4);
LRESULT ret;
ret = SendMessage (hWnd, Msg, wParam, lParam);
HMG_retnl ((LONG_PTR)
ret);
}
HMG_parnl, HMG_retnl
and LONG_PTR take a 32 or 64 bit value according to the chosen architecture.
HMG
defines a series of macros (INCLUDE\HMG_UNICODE.h)
that take a value of 32 or 64 bit according to the architecture chosen for
compiling:
- HMG_parnl
- HMG_parvnl
- HMG_retnl
- HMG_retnllen
- HMG_stornl
- HMG_storvnl
- HMG_arraySetNL
- HMG_arrayGetNL
Note: remember when you pass a value to these functions you should use LONG_PTR
or INT_PTR for type conversion instead
of LONG or INT. When the parameters or values returned are of 32-bits you
continue using hb_parnl, hb_parni,
hb_retnl, hb_retni, etc.
and continue the conversion of type with LONG or INT as usually.
|
WIN32 |
WIN64 |
|
|
char |
8 |
8 |
|
short |
16 |
16 |
|
int |
32 |
32 |
|
long |
32 |
32 |
|
long long |
64 |
64 |
|
size_t |
32 |
64 |
|
pointer |
32 |
64 |
|
Others(*) |
32 |
64 |
|
(*)
LONG_PTR, INT_PTR, WPARAM, LPARAM, LRESULT, etc. |
||