Opening an existing DocFile is very similar to creating one. You might think that the API call to open a DocFile would be StgOpenDocFile, but you'd be wrong... The API call is StgOpenStorage, remember that a DocFile is itself a storage i.e. the root storage, just as the root directory is itself a directory.
procedure TestOpen;
var
Hr : HResult;
RootStorage : IStorage;
begin
{Try open the DocFile}
Hr := StgOpenStorage( 'c:\Temp\MyDocFile.ole',
nil,
STGM_READWRITE or
STGM_DIRECT or STGM_SHARE_EXCLUSIVE,
nil,
0,
RootStorage
);
{Was is opened?}
if( SUCCEEDED( Hr ) ) then
begin
(* Success *)
end
else begin
(* Fail *)
end;
end;
Before opening a file you might want to check if it is in fact a DocFile. This is accomplished by using the StgIsStorageFile function. Pass the name of the file as the only parameter (UniCode string) and the function will return S_OK if it is a DocFile.
if( StgIsStorageFile( 'c:\Temp\MyDocFile.ole' ) <> S_OK ) then
ShowMessage( 'Not a doc file' )
else
ShowMessage( 'Valid DocFile' );
All information on these www pages is copyright (©) 1997 Andre .v.d. Merwe And may not be copied or mirrored without my permission.