Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 2.49 KB

WriteFile.md

File metadata and controls

76 lines (56 loc) · 2.49 KB

Home

Function name : WriteFile

Group: File Management - Library: kernel32


The WriteFile function writes data to a file and is designed for both synchronous and asynchronous operation.


Code examples:

Storing screen shot of a form to bitmap file
Storing content of the Clipboard to a bitmap file
Using InternetSetFilePointer when resuming interrupted download from the Internet
Using mailslots to send messages on the network
Subclassing CommandButton control to create BackColor property
Vertical Label control
Peer-to-peer LAN messenger built with Mailslot API functions
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
How to convert a bitmap file to monochrome format (1 bpp)
Using named pipes for interprocess communication

Declaration:

BOOL WriteFile(
  HANDLE hFile,                    // handle to file
  LPCVOID lpBuffer,                // data buffer
  DWORD nNumberOfBytesToWrite,     // number of bytes to write
  LPDWORD lpNumberOfBytesWritten,  // number of bytes written
  LPOVERLAPPED lpOverlapped        // overlapped buffer
);  

FoxPro declaration:

DECLARE INTEGER WriteFile IN kernel32;
	INTEGER   hFile,;
	INTEGER   lpBuffer,;
	INTEGER   nBt2Write,;
	INTEGER @ lpBtWritten,;
	INTEGER   lpOverlapped  

Parameters:

hFile [in] Handle to the file to be written to. The file handle must have been created with GENERIC_WRITE access to the file.

lpBuffer [in] Pointer to the buffer containing the data to be written to the file.

nNumberOfBytesToWrite [in] Specifies the number of bytes to write to the file.

lpNumberOfBytesWritten [out] Pointer to the variable that receives the number of bytes written.

lpOverlapped [in] Pointer to an OVERLAPPED structure. This structure is required if hFile was opened with FILE_FLAG_OVERLAPPED.


Return value:

If the function succeeds, the return value is nonzero.


Comments:

The function also can be used to put a message in a mailslot.