Contact Us Today!
443.276.5050

win32 API cheatsheet

Switching between Unix and Windows is hard... especially when your a lifelong Unix guy. I forget the Windows API calls about 5 minutes after I learn them... so here's a cheat sheet of useful API calls, much of this data is pulled from the book "Windows System Programming, Fourth Edition". It a good read if your new (or don't often use) Windows.

File related Functions
FunctionPurpose
CreateFileCreate a File Object
ReadFileRead a File Object
WriteFileWrite a File Object
CloseHandleClose a Handle (of which a file is)

Console Related functions (note GUI apps don't have a console by default)(40)
GetStdHandleGets a handle to STD_{INPUT|OUTPUT|ERROR}_HANDLE
SetStdHandleSets STD_{INPUT|OUTPUT|ERROR}_HANDLE to a handle
SetConsoleModeChange Console Settings
ReadConsoleRead from Console
WriteConsoleWrite to Console
FreeConsoleDetach a process from it's console
AllocConsoleCreate a new console for a process if it doesn't already have one

File and Directory Functions(46)
DeleteFileDeletes a file
CopyFileCopy a file
CreateHardLinkCreate a hard link
CreateSymbolicLinkCreate a symbolic link
MoveFile[Ex]Rename a file or directory
CreateDirectoryCreate a Directory
RemoveDirectoryRemove a Directory
SetCurrentDirectoryChange the current Directory
GetCurrentDirectoryGet the current Directory
FindFirstFileFile Searching... similar to Unix opendir
FindNextFileFile Searching... similar to Unix readdir
FindCloseClose search handle... similar to Unix closedir
GetFileInformationByHandleGetInformation about a file (like Unix stat)
GetFileTimeget time information about a file(like Unix stat)
FileTimeToSystemTime
SystemTimeToFileTime
CompareFileTime
SetFileTime
FileTimeToLocalFileTime
LocalFileTimeToFileTime
GetFileTypeTells what type of file something is (char, pipe etc)
GetFileAttributesDirectory, Normal File, Read Only, Temporary
SetFileAttributesDirectory, Normal File, Read Only, Temporary
GetTimeFileNameCreates a name for temp files
GetFullPathNameget the path name
GetShortPathNameget the path name
SetFileShortNamechange the existing filename

File Pointers(61)
SetFilePointer[Ex]Changes the file pointer for Random Access
GetFileSize[Ex]Get the file size
SetEndOfFile[Ex]Truncate or Grow files
File Locking(61)
LockFileExFile locking
UnlockFileExFile locking
Registry Functions (86)
RegOpenKey[Ex]Registry Handle for accesing registry
RegEnumKey[Ex]Like Unix opendir... for registry keys
RegCreateKey[Ex]Create a registry key
RegEnumValue[Ex]Get registry value information/TD>
RegSetValue[Ex]Set a registry value
RegDeleteValueSet a registry value

Random Information:

GetLastError

Strings - "This string" (ASCII 8 bit)
Strings - L"This string" (Unicode 16 bit)
Strings - _T("This string") (Macro to dynamically define TCHAR to ASCII (CHAR) or UNICODE (WCHAR) based on whether UNICODE and _UNICODE are defined or not)

_tmain() -> goes to main() or wmain() depending on [_]UNICODE defines

Need Solutions?
We've Got Answers!

We have experience in all type of enterprise solutions. From Unix/Linux engineering and Integration, network security, VoIP and network convergence, helping you virtualize your environment all the way to helping you train your IT staff! Give us a call.