This site is moving to The Zen Source Library
Please Update your bookmarks


Creating a DocFile, take two

Wasn't that fun? Lets get back to creating a DocFile shall we.

Here is the StgCreateDocFile function again


   function StgCreateDocFile(   Unicode filename,
                                STGM flags,
                                Reserved must be 0,
                                Storage returned
                             ) : HResult;

Unicode file name Full path and file name for the DocFile.

"c:\Temp\MyDocFile.ole"

STGM Flags We want to create a DocFile and have read write access to it. Here are the flags to use

STGM_CREATE or STGM_READWRITE or
STGM_DIRECT or STGM_SHARE_EXCLUSIVE

Reserved Nothing to taxing here….

0

Storage returned A reference parameter that will contain the storage if the function call is successful.

RootStorage


Here is a code snippet that uses creates a DocFile


   procedure TestCreate;
   var
      Hr : HResult;
      RootStorage : IStorage;
   begin
         {Try create the DocFile}
      Hr := StgCreateDocFile(  'c:\Temp\MyDocFile.ole',
                               STGM_CREATE or STGM_READWRITE or
                               STGM_DIRECT or STGM_SHARE_EXCLUSIVE,
                               0,
                               RootStorage
                             );

         {Was is created?}
      if(   SUCCEEDED(  Hr  )   ) then
      begin
 
         (* Success *)

      end
      else begin

         (*  Fail  *)

      end;
   end;


Delphi 1 and Delphi 2 users: dont forget to free the storage once you're finished with it.


   RootStorage.Release;

Delphi 3 users: The Release method has been renamed to _Release. You must not, however, call this function! Delphi does this for you automatically as soon as the variable goes out of scope or is used for another purpose. This is similar to Java's garbage collection, it makes using structured storage (and COM/OLE in general) a lot easier.






All information on these www pages is copyright (©) 1997 Andre .v.d. Merwe And may not be copied or mirrored without my permission.