OpenTextFile method


Prototype

OpenTextFile Proto lpszFileName:LPSTR, dwDesiredAcces:DWord, dwCreation:DWord

Syntax

Invoke OpenTextFile, lpszFileName, dwDesiredAcces, dwCreation

Function

Opens a file for reading and/or writing lines of text. The file name may be a full path.

Parameters

lpszFileName

Pointer to the effective address of a null-terminated string containing the file name to open.

dwDesiredAcces

Specifies the type of acces to the file. It can be any combination of the following values:

ecRead GENERIC_READ File is open for read access.
ecWrite GENERIC_WRITE File is open for write access.

dwCreation

Specifies which action to take when the file exists or when not. It can be any combination of the following values:

ecCreateNew CREATE_NEW Creates a new file. If the file exists, the method fails.
ecCreateAlways CREATE_ALWAYS Creates a new file. If the file exists, the method overwrites it.
ecOpenExisting OPEN_EXISTING Opens the file only if it exists.
ecOpenAlways OPEN_ALWAYS Opens the file if it exists. If not, the method creates it.
ecTruncateExisting TRUNCATE_EXISTING Opens the file and truncates it to zero bytes.

Return value

Eax returns an open handle to the specified file, or INVALID_HANDLE_VALUE if the file could not be open.


REMARKS
: With the open handle, you can call the
ReadTextLine and/or WriteTextLine methods to read and/or write lines of text. When you no longer need the file, close its handle by calling the CloseHandle API function.

REMARKS: The OpenTextFile method expects lpszFileName to be a Unicode string if the application is running as Unicode, or an ANSI string if not (see the IsAppUnicode method). You can call OpenTextFileA to open ANSI file names in Unicode applications, or OpenTextFileW to open Unicode file names in ANSI applications.