Data Access
This section provides documentation for APIs related to accessing and manipulating data within the Windows operating system and various data sources.
These functions allow you to interact with the file system, including creating, reading, writing, and deleting files.
CreateFileCreates 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.INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.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
}
WriteFileWrites data to a specified file or device. This function is the counterpart to ReadFile.
ReadFileReads data from a specified file or device into memory. It is often used in conjunction with CreateFile.
APIs for interacting with relational databases and other structured data sources.
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 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.
APIs for reading from and writing to the Windows Registry, which stores configuration settings.
RegOpenKeyExOpens an existing registry key. If the key does not exist, the function returns an error.
RegSetValueExCreates or updates a value under a registry key.
RegQueryValueExRetrieves the type and data for a specified registry value.