System Communication API Reference
This section details the Windows API functions and concepts related to inter-process communication (IPC) and system-level communication mechanisms.
Introduction to System Communication
Effective communication between different processes is crucial for building robust and efficient Windows applications. This documentation covers various methods, including:
- Pipes: Unidirectional or bidirectional data streams for communication between related processes.
- Message Queues: Asynchronous message passing between processes, often used for decoupled systems.
- Shared Memory: Allowing multiple processes to access the same region of memory for high-performance data sharing.
- Sockets: For network communication, both local and remote, using TCP/IP or other protocols.
- Windows Messages: The fundamental mechanism for intra-process and inter-process communication in Windows GUI applications.
- COM (Component Object Model): A powerful object-oriented framework for inter-process communication and software interoperability.
Core Communication APIs
CreatePipe
Description:
Creates an anonymous pipe, a unidirectional data stream. It returns handles to the read and write ends of the pipe. Useful for redirecting standard input/output of child processes.
Parameters:
hReadPipe: Pointer to a HANDLE variable that receives the read end of the pipe.hWritePipe: Pointer to a HANDLE variable that receives the write end of the pipe.lpPipeAttributes: A pointer to aSECURITY_ATTRIBUTESstructure that specifies the security attributes of the new pipe.nSize: The buffer size for the pipe, in bytes.
Return Value:
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
CreateFileMapping
Description:
Creates or opens a named or unnamed file mapping object. This is the first step in creating shared memory.
Parameters:
hFile: A handle to the file that will be used to initialize the size of the memory-mapped file.lpFileMappingAttributes: Security attributes.flProtect: Memory protection for the pages of the file mapping object.dwMaximumSizeHigh,dwMaximumSizeLow: High and low parts of the maximum size of the memory-mapped file.lpName: The name of the mapping object.
Return Value:
If the function succeeds, the return value is a handle to the newly created file mapping object. If the function fails, the return value is NULL.
MapViewOfFile
Description:
Maps a view of a file mapping into the address space of the calling process. This function is used to access shared memory.
Parameters:
hFileMappingObject: Handle to a file mapping object.dwDesiredAccess: Access to the mapped views.dwFileOffsetHigh,dwFileOffsetLow: Offset into the file mapping.dwNumberOfBytesToMap: Number of bytes to map.
Return Value:
If the function succeeds, the return value is the starting address of the mapped view of the specified file. If the function fails, the return value is NULL.
PostMessage
Description:
Places (posts) a message into the message queue of the specified thread or an array of threads. Unlike SendMessage, this function returns immediately and does not wait for the destination thread to process the message.
Parameters:
hWnd: Handle to the destination window.Msg: The message to be posted.wParam: Additional message-specific information.lParam: Additional message-specific information.
Return Value:
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
CreateThread
Description:
Creates a new thread to execute within the virtual address space of the calling process. Threads are fundamental for concurrent operations and can be used to handle communication tasks asynchronously.
Parameters:
lpThreadAttributes: Security attributes.dwStackSize: Initial size of the thread stack.lpStartAddress: Pointer to the application-defined function.lpParameter: Argument for the thread function.dwCreationFlags: Control flags.lpThreadId: Receives the thread identifier.
Return Value:
If the function succeeds, the return value is a handle to the new thread. If the function fails, the return value is NULL.
Further Reading
Explore related topics: