Sourcecode and Code Snippets
3 minute read •
Presented here are a collection of sourcecode snippets and mini-projects. All downloads are plain Win32 C and C++, and compile under Microsoft Visual Studio 6.0.
Code Snippets
A collection of C and C++ programming snippets organised into categories of functionality.
Win32 Sourcecode projects
Sourcecode downloads which implement full applications or utilities. First published around 2001-2005.
Global Titlebar Hook | Insert buttons into window titlebars on a global level (system-wide). Handles XP Themes if available. Requires NT/2000/XP. |
WinCap3 | Capture hidden and obscured windows - proof of concept demo application. Windows XP only - will not work under Win95/98/ME. Might work under NT,2000 but untested. Click here and here for old versions. |
ReportView | Force Report-style view in all Open and Save common dialogs. |
Directory Tree | Display a directory hierarchy using ASCII graphics (ala the “tree” DOS command). |
Process Tree | Display a process hierarchy like SysInternal’s ProcessExplorer. |
SetRes | Control multiple display resolutions and colour depths with this useful tool. |
Win32 Sourcecode snippets
A collection of useful functions which I’ve accumulated over the years.
AttachDesktop | Attach to a specified desktop |
RegHelper | Registry utilities which mimic the GetPrivateProfile_xxx APIs |
EnableDebug | Enable SE_DEBUG_NAME and other system privileges (useful for opening system processes) |
C++ Socket Library | C++ class wrappers around the winsock library - makes socket programming much easier! |
Trace macro | “printf” style wrapper around the OutputDebugString API |
DragFile | Filename Drag+Drop the Windows 3.1 way |
Alpha-blended windows | Simple functions to provide alpha-blended window support. |
Styles | Helper functions to set window and dialog item styles, using SetWindowLong. |
ForceSetForegroundWindow | SetForegroundWindow replacement (that works!) |
EnableDialogTheme | Enable XP themes on dialog boxes |
GetVersionString | Howto retrieve version strings (e.g. File description) from an executable’s version resources. |
Windows NT sourcecode
The following sourcecode snippets are specific to the Windows NT family of operating systems - Windows NT, 2000, XP and 2003 Server. Many of the downloads are heavily influenced by USENET threads, in particular postings by Gary Nebbett.
SetConsolePalette | Modify the Win32 Console’s palette dynamically at runtime. |
CreateToken | Create an access token for local user accounts without knowing the password - requires SeCreateTokenPrivilege level. You also require a custom ntdll.h if you don’t already have one. Gary Nebbet original author. |
QuerySystemInfo | Wrapper around the ZwQuerySystemInformation native system service. |
UsernameToSid | Convert a username to SID |
KMem | Read kernel memory from usermode (kmemcpy function). Gary Nebbet original author. |
InjectThread | CreateRemoteThread replacement, can inject into an already-running thread. View the example usage. |
BreakPoint | Hardware breakpoint and single-step debugging routines. |
Windows NT Device Driver snippets
Windows NT kernel-mode snippets.
IsrSpinlock | Howto acquire a spinlock at any IRQL level - implemented as a custom spinlock |
InterlockedExecute | Acquire exclusive access to all CPUs and execute a single function with full system lock. Please send feedback on this technique if you find it useful! |