Win 32 Programming Jim Fawcett CSE 775 Distributed
Win 32 Programming Jim Fawcett CSE 775 – Distributed Objects Spring 2016
References n Programming Applications for Microsoft Windows, 4 th Edition, Jeffrey Richter, Microsoft Press, 1999 n Unicode, More Unicode n Win 32 Code Tips n www. Catch 22. net n Tips #1, Tips #2, Tutorials n Windows SDK Issues 2
Topics n Important header files n Errors n Win 32 Types n Unicode – coming later n Win 32 API 3
Important Windows Header Files n Important header files in Platform. SDK folder n Windows. h Includes other headers n Commdlg. h Common controls (COM based) n Dlgs. h Dialog definitions n OLE 2. h COM definitions n Shell. API. h Shell API n Sh. Folder. h Folder definitions n Winbase. h Managing processes n Windef. h Windows type definitions n Win. User Windows messages n Many other headers n Win. Error. h Error codes and strings n Winsock 2. h sockets n MSHTML. h Browser Control definitions and IE DOM handling n Important header files in VC folder n Process. h Threading 4
Win 32 API Error Protocols Error code returned from API function call Data Type Meaning VOID Function cannot fail BOOL If function fails value is zero; otherwise nonzero. HANDLE If the function fails usually value is NULL; otherwise valid handle to kernel object. Some functions return INVALID_HANDLE on failure. PVOID LONG/DWORD If the function fails, value is NULL; otherwise PVOID points to a memory address to be manipulated. Usually indicates a count is returned. If counting fails, function usually returns -1 or 0. Check the platform SDK documentation. 5
Data Types Windows Type Equivalent LPVOID void* LPSTR wchar_t* TCHAR char or wchar_t LPTSTR char* or wchar_t* DWORD unsigned 32 bit integer WORD unsigned 16 bit integer HANDLE Windows handle HINSTANCE Handle to program instance HMODULE Handle to loaded DLL HMENU Menu handle WPARAM 16 bit parameter LPARAM 32 bit parameter 6
Win 32 API n Path to documentation n n Windows API Reference: MSDN Library > Development Tools and Languages > Windows API Windows Data Types: MSDN Library > Windows Development > Getting Started > Using Windows Headers > Windows Data Types System Services (DLLs and Processes, File Services, …): MSDN Library > Windows Development > System Services User Interface (Windows Controls, Windows Shell, …) MSDN Library > Windows Development > Windows Application UI Development n C-Style functions often with extended versions 7
Win 32 API – Extended Functions n Example – extended function n Read. File BOOL Read. File( HANDLE h. File, LPVOID lp. Buffer, DWORD n. Number. Of. Bytes. To. Read, LPDWORD lp. Number. Of. Bytes. Read, LPOVERLAPPED lp. Overlapped ); n Read. File. Ex BOOL Read. File. Ex( HANDLE h. File, LPVOID lp. Buffer, DWORD n. Number. Of. Bytes. To. Read, LPOVERLAPPED lp. Overlapped, LPOVERLAPPED_COMPLETION_ROUTINE lp. Completion. Routine ); 8
Win 32 API by Function n File services n Disk, Volume, Directory, and File management n Windows System Information n Handles, Objects, Registry, System Info, Time n DLLs, Processes, and Threads n DLLs, Processes and Threads, Services, Synchronization n Memory Management n Reserving and committing memory, File Mapping n Interprocess Communication n Mailslots, Network DDE (deprecated), Pipes 9
Files n File Management n Create. File, Open. File, Close. Handle, Replace. File n Read. File(Ex), Write. File(Ex), Copy. File(Ex), Delete. File, Move. File(Ex) n Find. First. File(Ex), Find. Next. File, Find. Close, Search. Path n Get. File. Attributes(Ex), Set. File. Attributes, Get. File. Size(Ex) n Get. Full. Path. Name n Lock. File(Ex), Unlock. File(Ex) 10
Directories n Directory Management Functions n Create. Directory(Ex), Remove. Directory n Get. Current. Directory, Set. Current. Directory n Find. First. Change. Notification, Find. Next. Change. Notification, Find. Close. Change. Notification 11
Registry n Registry Functions n Reg. Create. Key. Ex, Reg. Open. Key. Ex, Reg. Close. Key, Reg. Delete. Key(Ex), Reg. Delete. Key. Value, Reg. Replace. Key, Reg. Restore. Key, Reg. Save. Key(Ex), Reg. Query. Value. Ex n Reg. Get. Value, Reg. Set. Value. Ex, Reg. Delete. Value, Reg. Set. Key. Value n Reg. Load. Key, Reg. Unload. Key n Reg. Enum. Key. Ex, Reg. Enum. Value n Reg. Copy. Tree, Reg. Delete. Tree 12
Dynamic-Link Libraries n Dynamic-Link Library Functions n Dll. Main n Load. Library(Ex), Free. Library, Get. Proc. Address n Get. Dll. Directory, Set. Dll. Directory n Get. Module. File. Name(Ex), Get. Module. Handle(Ex) 13
Processes n Process Functions n Create. Process, Open. Process, Exit. Process, Get. Exit. Code. Process, Get. Startup. Info, Terminate. Process n Enum. Processes, Process 32 First, Process 32 Next n Get. Current. Process, Get. Current. Process. Id n Get. Process. Id, Get. Process. Handle. Count n Get. Command. Line, Get. Environment. Strings, Get. Environment. Variable, Set. Environment. Variable, Get. Gui. Resources 14
Threads n Thread Functions n Create. Thread, Open. Thread, Thread. Proc n n don’t use if you call C/C++ libraries Use _beginthread(Ex) Create. Remote. Thread, Exit. Thread, Resume. Thread, Terminate. Thread, Get. Exit. Code. Thread n Sleep(Ex), Wait. For. Input. Idle n Get. Current. Thead, Get. Current. Thread. Id n Get. Thread. Priority, Set. Thread. Priority n Tls. Alloc, Tls. Free, Tls. Get. Value, Tls. Set. Value n 15
C Run-Time Library Thread Functions n Thread functions n _beginthread(Ex), _endthread(ex) 16
Virtual to Physical Mapping 17
Memory Management n Memory Management Functions n Used by COM – Allocates on heap Global. Alloc, Global. Re. Alloc, Global. Lock, Global. Unlock, Global. Free, Global. Handle n Newer Heap Management – not movable Heap. Alloc, Heap. Compact, Heap. Create, Heap. Destroy, Get. Process. Heap(s) n Copy. Memory, Fill. Memory, Move. Memory n Memory Mapped Files Create. File. Mapping, Open. File. Mapping, Map. View. Of. File(Ex), Flush. View. Of. File, Unmap. View. Of. File n Virtual Memory Virtual. Alloc(Ex), Virtual. Free(Ex) 18
Fini 19
- Slides: 19