Windows API Reference

Data Access

Data Access APIs

This section provides documentation for APIs related to accessing and manipulating data within the Windows operating system and various data sources.

File I/O Functions

These functions allow you to interact with the file system, including creating, reading, writing, and deleting files.

CreateFile

Creates or opens a file or I/O device. It provides detailed control over file access and sharing.

HANDLE CreateFile( LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile );

Parameters:

  • lpFileName: The name of the file or device.
  • dwDesiredAccess: The access to the file or device, specified as one or more of the generic access rights.
  • dwShareMode: A zero or more of the following values, which can be used in any combination to mask accesses to the object and indicate whether subsequent open-requests can have access to it.
  • lpSecurityAttributes: A pointer to a SECURITY_ATTRIBUTES structure that contains security information for the file.
  • dwCreationDisposition: Determines the action to be taken if the file or device exists or does not exist.
  • dwFlagsAndAttributes: The file system attributes and flags for the file or device.
  • hTemplateFile: A handle to a template file with the GENERIC_READ access right.
Return Value:
If the function succeeds, the return value is an open handle to the specified file or device. If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
Important: Always close file handles obtained from CreateFile using CloseHandle to release system resources.
// Example: Opening a file for reading
            HANDLE hFile = CreateFile(
                L"C:\\path\\to\\my\\file.txt",
                GENERIC_READ,
                FILE_SHARE_READ,
                NULL,
                OPEN_EXISTING,
                FILE_ATTRIBUTE_NORMAL,
                NULL
            );

            if (hFile == INVALID_HANDLE_VALUE) {
                // Handle error
                DWORD error = GetLastError();
                // ... process error ...
            } else {
                // Successfully opened file, proceed with reading...
                CloseHandle(hFile); // Remember to close the handle
            }

WriteFile

Writes data to a specified file or device. This function is the counterpart to ReadFile.

ReadFile

Reads data from a specified file or device into memory. It is often used in conjunction with CreateFile.

Database Access (ODBC/OLE DB)

APIs for interacting with relational databases and other structured data sources.

Open Database Connectivity (ODBC)

ODBC is a standard API for accessing database management systems (DBMS). It provides a way to access data in a uniform manner, regardless of which DBMS is being used.

OLE DB

OLE DB is a set of Microsoft COM interfaces that provides a consistent, high-performance interface for accessing data from a variety of information sources. It is designed to be more flexible and efficient than ODBC for certain scenarios.

Registry Access Functions

APIs for reading from and writing to the Windows Registry, which stores configuration settings.

RegOpenKeyEx

Opens an existing registry key. If the key does not exist, the function returns an error.

RegSetValueEx

Creates or updates a value under a registry key.

RegQueryValueEx

Retrieves the type and data for a specified registry value.