| [Alb-Net home] | [AMCC] | [KCC] | [other mailing lists] |
List: Info-Tech[Info-tech] RE: RE: Ndihma ne VBFitim Skenderi fitims at syntelate.comMon May 15 04:33:34 EDT 2000
Strukturat jane te nevojshme per te mundesuar thirrjen e API funksioneve
ne Windows. Kurse deklarimet e funksioneve nevoiten per ti tregruar VB
se ne cilen librari sistemore (DLL) ndodhen ato funksione. Teksti i
meposhtem i spjegon ato funksione:
OpenFile
The OpenFile function creates, opens, reopens, or deletes a file.
Note This function is provided only for compatibility with 16-bit
versions of Windows. Win32-based applications should use the CreateFile
function.
HFILE OpenFile(
LPCSTR lpFileName, // file name
LPOFSTRUCT lpReOpenBuff, // file information
UINT uStyle // action and attributes
);
Parameters
lpFileName
[in] Pointer to a null-terminated string that names the
file to be opened. The string must consist of characters from the
Windows 3.x character set. The OpenFile function does not support
Unicode file names. Also, OpenFile does not support opening named pipes.
lpReOpenBuff
[out] Pointer to the OFSTRUCT structure that receives
information about the file when it is first opened. The structure can be
used in subsequent calls to the OpenFile function to refer to the open
file.
The OFSTRUCT structure contains a pathname string member
whose length is limited to OFS_MAXPATHNAME characters. OFS_MAXPATHNAME
is currently defined to be 128. Because of this, you cannot use the
OpenFile function to open a file whose path length exceeds 128
characters. The CreateFile function does not have such a path length
limitation.
uStyle
[in] Specifies the action to take. This parameter can be
one or more of the following values.
Value Meaning
OF_CANCEL Ignored. In the Win32 API, OF_PROMPT produces a dialog
box containing a Cancel button.
OF_CREATE Creates a new file. If the file already exists, it is
truncated to zero length.
OF_DELETE Deletes the file.
OF_EXIST Opens the file and then closes it. Used to test for a
file's existence.
OF_PARSE Fills the OFSTRUCT structure but carries out no other
action.
OF_PROMPT Displays a dialog box if the requested file does not
exist. The dialog box informs the user that the system cannot find the
file, and it contains Retry and Cancel buttons. Choosing the Cancel
button directs OpenFile to return a file-not-found error message.
OF_READ Opens the file for reading only.
OF_READWRITE Opens the file for reading and writing.
OF_REOPEN Opens the file using information in the reopen buffer.
OF_SHARE_COMPAT For MS-DOS-based file systems using the Win32 API, opens
the file with compatibility mode, allowing any process on a specified
computer to open the file any number of times. Other efforts to open
with any other sharing mode fail. Windows NT/2000: This flag is mapped
to the CreateFile function's FILE_SHARE_READ | FILE_SHARE_WRITE flags.
OF_SHARE_DENY_NONE Opens the file without denying read or write
access to other processes. On MS-DOS-based file systems using the Win32
API, if the file has been opened in compatibility mode by any other
process, the function fails. Windows NT/2000: This flag is mapped to
the CreateFile function's FILE_SHARE_READ | FILE_SHARE_WRITE flags.
OF_SHARE_DENY_READ Opens the file and denies read access to other
processes. On MS-DOS-based file systems using the Win32 API, if the file
has been opened in compatibility mode or for read access by any other
process, the function fails. Windows NT/2000: This flag is mapped to
the CreateFile function's FILE_SHARE_WRITE flag.
OF_SHARE_DENY_WRITE Opens the file and denies write access to other
processes. On MS-DOS-based file systems using the Win32 API, if the file
has been opened in compatibility mode or for write access by any other
process, the function fails. Windows NT/2000: This flag is mapped to
the CreateFile function's FILE_SHARE_READ flag.
OF_SHARE_EXCLUSIVE Opens the file with exclusive mode, denying both
read and write access to other processes. If the file has been opened in
any other mode for read or write access, even by the current process,
the function fails.
OF_VERIFY Verifies that the date and time of the file are the same
as when it was previously opened. This is useful as an extra check for
read-only files.
OF_WRITE Opens the file for writing only.
Return Values
If the function succeeds, the return value specifies a file handle.
If the function fails, the return value is HFILE_ERROR. To get extended
error information, call GetLastError.
Remarks
If the lpFileName parameter specifies a file name and extension only,
this function searches for a matching file in the following directories,
in the order shown:
1. The directory from which the application loaded.
2. The current directory.
3. Windows 95: The Windows system directory. Use the
GetSystemDirectory function to get the path of this directory.
Windows NT/2000: The 32-bit Windows system directory.
Use the GetSystemDirectory function to get the path of this directory.
The name of this directory is SYSTEM32.
4. Windows NT/2000: The 16-bit Windows system directory.
There is no Win32 function that obtains the path of this directory, but
it is searched. The name of this directory is SYSTEM.
5. The Windows directory. Use the GetWindowsDirectory
function to get the path of this directory.
6. The directories that are listed in the PATH environment
variable.
The lpFileName parameter cannot contain wildcard characters.
The 32-bit OpenFile function does not support the OF_SEARCH flag
supported by the 16-bit Windows OpenFile function. The OF_SEARCH flag
directs the system to search for a matching file even when the file name
includes a full path. To search for a file in a Win32-based application,
use the SearchPath function.
To close the file after use, call the _lclose function.
Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Read File
The ReadFile function reads data from a file, starting at the position
indicated by the file pointer. After the read operation has been
completed, the file pointer is adjusted by the number of bytes actually
read, unless the file handle is created with the overlapped attribute.
If the file handle is created for overlapped input and output (I/O), the
application must adjust the position of the file pointer after the read
operation.
BOOL ReadFile(
HANDLE hFile, // handle to file
LPVOID lpBuffer, // data buffer
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // number of bytes read
LPOVERLAPPED lpOverlapped // overlapped buffer
);
Parameters
hFile
[in] Handle to the file to be read. The file handle must
have been created with GENERIC_READ access to the file.
Windows NT/2000: For asynchronous read operations, hFile
can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the
CreateFile function, or a socket handle returned by the socket or accept
function.
Windows 95/98: For asynchronous read operations, hFile
can be a communications resource opened with the FILE_FLAG_OVERLAPPED
flag by CreateFile, or a socket handle returned by socket or accept. You
cannot perform asynchronous read operations on mailslots, named pipes,
or disk files.
lpBuffer
[out] Pointer to the buffer that receives the data read
from the file.
nNumberOfBytesToRead
[in] Specifies the number of bytes to be read from the
file.
lpNumberOfBytesRead
[out] Pointer to the variable that receives the number
of bytes read. ReadFile sets this value to zero before doing any work or
error checking. If this parameter is zero when ReadFile returns TRUE on
a named pipe, the other end of the message-mode pipe called the
WriteFile function with nNumberOfBytesToWrite set to zero.
Windows NT/2000: If lpOverlapped is NULL,
lpNumberOfBytesRead cannot be NULL. If lpOverlapped is not NULL,
lpNumberOfBytesRead can be NULL. If this is an overlapped read
operation, you can get the number of bytes read by calling
GetOverlappedResult. If hFile is associated with an I/O completion port,
you can get the number of bytes read by calling
GetQueuedCompletionStatus.
Windows 95/98: This parameter cannot be NULL.
lpOverlapped
[in] Pointer to an OVERLAPPED structure. This structure
is required if hFile was created with FILE_FLAG_OVERLAPPED.
If hFile was opened with FILE_FLAG_OVERLAPPED, the
lpOverlapped parameter must not be NULL. It must point to a valid
OVERLAPPED structure. If hFile was created with FILE_FLAG_OVERLAPPED and
lpOverlapped is NULL, the function can incorrectly report that the read
operation is complete.
If hFile was opened with FILE_FLAG_OVERLAPPED and
lpOverlapped is not NULL, the read operation starts at the offset
specified in the OVERLAPPED structure and ReadFile may return before the
read operation has been completed. In this case, ReadFile returns FALSE
and the GetLastError function returns ERROR_IO_PENDING. This allows the
calling process to continue while the read operation finishes. The event
specified in the OVERLAPPED structure is set to the signaled state upon
completion of the read operation.
If hFile was not opened with FILE_FLAG_OVERLAPPED and
lpOverlapped is NULL, the read operation starts at the current file
position and ReadFile does not return until the operation has been
completed.
Windows NT/2000: If hFile is not opened with
FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the read operation
starts at the offset specified in the OVERLAPPED structure. ReadFile
does not return until the read operation has been completed.
Windows 95/98: For operations on files, disks, pipes, or
mailslots, this parameter must be NULL; a pointer to an OVERLAPPED
structure causes the call to fail. However, Windows 95/98 supports
overlapped I/O on serial and parallel ports.
Return Values
The ReadFile function returns when one of the following is true: a write
operation completes on the write end of the pipe, the number of bytes
requested has been read, or an error occurs.
If the function succeeds, the return value is nonzero.
If the return value is nonzero and the number of bytes read is zero, the
file pointer was beyond the current end of the file at the time of the
read operation. However, if the file was opened with
FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the return value is
FALSE and GetLastError returns ERROR_HANDLE_EOF when the file pointer
goes beyond the current end of file.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
If part of the file is locked by another process and the read operation
overlaps the locked portion, this function fails.
An application must meet certain requirements when working with files
opened with FILE_FLAG_NO_BUFFERING:
* File access must begin at byte offsets within the file
that are integer multiples of the volume's sector size. To determine a
volume's sector size, call the GetDiskFreeSpace function.
* File access must be for numbers of bytes that are
integer multiples of the volume's sector size. For example, if the
sector size is 512 bytes, an application can request reads and writes of
512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes.
* Buffer addresses for read and write operations must be
sector aligned (aligned on addresses in memory that are integer
multiples of the volume's sector size). One way to sector align buffers
is to use the VirtualAlloc function to allocate the buffers. This
function allocates memory that is aligned on addresses that are integer
multiples of the system's page size. Because both page and volume sector
sizes are powers of 2, memory aligned by multiples of the system's page
size is also aligned by multiples of the volume's sector size.
Accessing the input buffer while a read operation is using the buffer
may lead to corruption of the data read into that buffer. Applications
must not read from, write to, reallocate, or free the input buffer that
a read operation is using until the read operation completes.
Characters can be read from the console input buffer by using ReadFile
with a handle to console input. The console mode determines the exact
behavior of the ReadFile function.
If a named pipe is being read in message mode and the next message is
longer than the nNumberOfBytesToRead parameter specifies, ReadFile
returns FALSE and GetLastError returns ERROR_MORE_DATA. The remainder of
the message may be read by a subsequent call to the ReadFile or
PeekNamedPipe function.
When reading from a communications device, the behavior of ReadFile is
governed by the current communication time-outs as set and retrieved
using the SetCommTimeouts and GetCommTimeouts functions. Unpredictable
results can occur if you fail to set the time-out values. For more
information about communication time-outs, see COMMTIMEOUTS.
If ReadFile attempts to read from a mailslot whose buffer is too small,
the function returns FALSE and GetLastError returns
ERROR_INSUFFICIENT_BUFFER.
If the anonymous write pipe handle has been closed and ReadFile attempts
to read using the corresponding anonymous read pipe handle, the function
returns FALSE and GetLastError returns ERROR_BROKEN_PIPE.
The ReadFile function may fail and return ERROR_INVALID_USER_BUFFER or
ERROR_NOT_ENOUGH_MEMORY whenever there are too many outstanding
asynchronous I/O requests.
The ReadFile code to check for the end-of-file condition (eof) differs
for synchronous and asynchronous read operations.
When a synchronous read operation reaches the end of a file, ReadFile
returns TRUE and sets *lpNumberOfBytesRead to zero. The following sample
code tests for end-of-file for a synchronous read operation:
// Attempt a synchronous read operation.
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ;
// Check for end of file.
if (bResult && nBytesRead == 0, )
{
// we're at the end of the file
}
An asynchronous read operation can encounter the end of a file during
the initiating call to ReadFile, or during subsequent asynchronous
operation.
If EOF is detected at ReadFile time for an asynchronous read operation,
ReadFile returns FALSE and GetLastError returns ERROR_HANDLE_EOF.
If EOF is detected during subsequent asynchronous operation, the call to
GetOverlappedResult to obtain the results of that operation returns
FALSE and GetLastError returns ERROR_HANDLE_EOF.
To cancel all pending asynchronous I/O operations, use the CancelIo
function. This function only cancels operations issued by the calling
thread for the specified file handle. I/O operations that are canceled
complete with the error ERROR_OPERATION_ABORTED.
If you are attempting to read from a floppy drive that does not have a
floppy disk, the system displays a message box prompting the user to
retry the operation. To prevent the system from displaying this message
box, call the SetErrorMode function with SEM_NOOPENFILEERRORBOX.
Fitim Skenderi
Senior Software Development Specialist - CT Products
Visit us on the web at: http://www.inisoft.co.uk
Tel: +44 (0)141 552 8800 Fax: +44 (0)141 553 1893
This document should only be read by those persons to whom it is
addressed and is not intended to be relied upon by any person without
subsequent written confirmation of its contents.
If you have received this E-mail message in error, please
notify us immediately by telephone on +44 (0)141 552 8800
More information about the Info-Tech mailing list |