Program Development using Unix Win32 API

Contents

Win32
Types
Examples
">

Win32

Win32 is the API for Microsoft Windows 32-bit programming for Windows95 and Windows NT. Windows95 is a subset of Windows NT for this API. Some other components of Win32 do not work across all versions of Windows: for example, the DOS file system does not have all the attributes of the NT file system. Nevertheless, most of the API works across all the Windows platforms in the same way.

Types

Win32 uses an extended set of data types, using C's typedef mechanism These include
BYTE unsigned 8 bit integer
DWORD 32 bit unsigned integer
LONG 32 bit signed integer
LPDWORD 32 bit pointer to DWORD
LPCSTR 32 bit pointer to constant character string
LPSTR 32 bit pointer to character string
UINT 32 bit unsigned int
WORD 16 bit unsigned int
HANDLE opaque pointer to system data

The Win32 documentation is available online through the Microsoft Developer Studio.

API specification files are used in C programs by the

#include <...>
mechanism.

Values about sizes of primitive data types is stored in <limits.h>

Examples

The following are simple examples of services offered in Win32 that do not require much background.

GetUserName()

The function GetUserName() is defined by
#include <windows.h>

BOOL GetUserName(LPTSRT buffer, LPDWORD bufferLen)
It places the user name into the buffer, and returns TRUE on success. It modifies the bufferLen value to the length of the name.

GetEnvironmentVariable

The environment holds the values of shell variables that may be accessible to the program. The function
#include <stdlib.h>

DWORD GetEnvironmentVariable(LPCTSRT name, LPTSTR buffer, DWORD bufferLen)
takes the environment variable as first parameter and sets the value in the buffer. The length of the value is returned, or zero on error.

GetSystemTime

This is used to get the system time
#include <windows.h>

VOID GetSystemTime(LPSYSTEMTIME time)
This uses a structure
typedef struct _SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
and is used by
Home Program Development using Unix Home
Jan Newmarch (http://jan.newmarch.name) <jan@newmarch.name>

Copyright © Jan Newmarch
Last modified: Wed Nov 19 19:00:40 EST 1997