... | ... | @@ -15,6 +15,8 @@ Table of Contents |
|
|
+ [Notification callback procedure](#notification-callback-procedure)
|
|
|
+ [Time and timer](#time-and-timer)
|
|
|
- [Writing Portable Code](#writing-portable-code)
|
|
|
* [Use correct data types](#use-correct-data-types)
|
|
|
* [Invalid pointer values](#invalid-pointer-values)
|
|
|
|
|
|
## Overview
|
|
|
|
... | ... | @@ -258,6 +260,32 @@ typedef BOOL (* TIMERPROC)(HWND, LINT, DWORD) |
|
|
|
|
|
## Writing Portable Code
|
|
|
|
|
|
Note that you should use `(-1)` instead of `0xFFFFFFFF` for the invalid
|
|
|
integer or pointer type value for good portability.
|
|
|
In this section, we give some tips for writing portable code.
|
|
|
|
|
|
### Use correct data types
|
|
|
|
|
|
When we read/write data from/to a file, we must use the data types suffixed
|
|
|
by 16, 32, or 64. For example, the following code writes a Windows BMP
|
|
|
file header to a file:
|
|
|
|
|
|
```cpp
|
|
|
MGUI_RWwrite (fp, &bmfh.bfType, sizeof (WORD16), 1);
|
|
|
MGUI_RWwrite (fp, &bmfh.bfSize, sizeof (DWORD32), 1);
|
|
|
MGUI_RWwrite (fp, &bmfh.bfReserved1, sizeof (WORD16), 1);
|
|
|
MGUI_RWwrite (fp, &bmfh.bfReserved2, sizeof (WORD16), 1);
|
|
|
MGUI_RWwrite (fp, &bmfh.bfOffBits, sizeof (DWORD32), 1);
|
|
|
```
|
|
|
|
|
|
### Invalid pointer values
|
|
|
|
|
|
We often use `NULL` for an invalid pointer type value. However, we may
|
|
|
also use `0xFFFFFFFF` for this purpose. This works on 32-bit architecture,
|
|
|
but not 64-bit.
|
|
|
|
|
|
Instead, we sugguest to use `(-1)` instead of `0xFFFFFFFF` for the invalid
|
|
|
integer or pointer type value for good portability:
|
|
|
|
|
|
```cpp
|
|
|
#define HDC_INVALID ((HDC)-1)
|
|
|
```
|
|
|
|