Opening and Attaching File
|
|
|
Having IXFile object created and initialized, we can open or attach file which we will operate on. To open file,
either Open or OpenAdvanced method can be used
depending on how much control over access mode is required. Open is used whenever file access and share mode
can be solely determined by mode of operation of the object. Developer does not have to specify access mode and other
file related parameters because these parameters result from mode of operation of the object specified during initialization.
This means that you do not have direct control over file access mode. Such behaviour may not be, in some situations, appropriate.
For example when file must be opened for shared access with manual locking only; in such case Open method opens file for exclusive access,
because automatic file locking is disabled. Instead, OpenAdvanced should be used
which gives you complete control over file access and sharing mode, creation disposition, attributes and flags. Keep in mind, however,
that it is your responsibilty to specify correct parameters for proper operation.
Name of the file for both methods can be specified as either absolute or relative path; if relative path is used
GetName method can be called to get fully qualified path. To obtain system handle of the opened file
GetFile method should be called; handle can be passed to any Windows file access function that expects file handle as a parameter.
Attach method is typically used in situations when operation must be performed on file that is already
opened by another code that return file handle. This handle must be valid system handle obtained from Windows functions. Please note that
file should be opened in access mode compatible with mode of operation of the object in order to read/write operations perform correctly.
When file is no longer needed it should be closed to release resources. Files can be closed either automatically or manually.
Automatic file closing occurs when object is initialized with autoclose feature enabled and is performed whenever new file is attached
to the object or object is being destroyed. Close method can be used any time to unconditionally close file.
In either case data buffers are flushed to the file and written to disk.
Examples
C++
int main(int, char**)
{
IFile ixf1;
IXFile *ixf2, *ixf3;
HANDLE h2;
ixf2 = new IXFile();
ixf3 = new IXFile();
ixf1.SetLicenseKey("YOURLICENSEKEY");
ixf2->SetLicenseKey("YOURLICENSEKEY");
ixf3->SetLicenseKey("YOURLICENSEKEY");
ixf1.Initialize();
ixf2->Initialize(IXF_MODE_READ | IXF_MODE_READLOCK);
ixf3->Initialize(IXF_MODE_RDWR | IXF_MODE_CLOSE, 1024);
ixf1.Open("test1.bin", FALSE, TRUE);
ixf2->Attach(h2);
ixf3->OpenAdvancedAttach("test3.bin", IXF_FILE_RDWR, IXF_FILE_SHARE_RDWR, IXF_FILE_OPEN_CREATE, IXF_FILE_NORMAL, 10);
.
.
.
ixf1.Open("test4.bin",TRUE,FALSE);
delete ixf2;
ixf3->Close();
delete ixf3;
return(0);
}
BASIC
Sub Main()
Dim ixf1 As IXFile, ixf2 As IXFile, ixf3 As IXFile
Dim h2 As Long
Set ixf1 = New IXFile
Set ixf2 = New IXFile
Set ixf3 = New IXFile
ixf1.SetLicenseKey "YOURLICENSEKEY"
ixf2.SetLicenseKey "YOURLICENSEKEY"
ixf3.SetLicenseKey "YOURLICENSEKEY"
ixf1.Initialize
ixf2.Initialize IXF_MODE_READ Or IXF_MODE_READLOCK
ixf3.Initialize IXF_MODE_RDWR Or IXF_MODE_CLOSE, 1024
ixf1.Open "test1.bin", False, True
ixf2.Attach h2
ixf3.OpenAdvancedAttach "test3.bin", IXF_FILE_RDWR, IXF_FILE_SHARE_RDWR, IXF_FILE_OPEN_CREATE, IXF_FILE_NORMAL, 10
.
.
.
ixf1.Open "test4.bin", TRUE, FALSE
.
.
.
Set ixf1 = Nothing
ixf3.Close
End Sub
See Also
Open,
OpenAdvanced,
Attach,
Detach,
Close,
GetName,
GetFile,
GetTimeStamp