Has anyone here done anything with the Volume Shadow Copy Service APIs? I have the article and sample code from The Delphi Magazine, from 9/2005, and have made the slight changes necessary to achieve a build, but the demo app does not work properly.

Comments

  1. In this routine, for example:
    procedure TVSSMainForm.IsSnapshottedButtonClick(Sender: TObject);
    Var
      Result       : Bool;
      Capabilities : Integer;
    begin
      OleCheck(IsVolumeSnapshotted(VolumeNameEdit.Text,Result,Capabilities));
      ShowMessage('Results for volume '+VolumeNameEdit.Text+#13#10#13#10+
                  'Snapshots present: '+BoolToStr(Result,True)+#13#10+
                  'Capabilities: '+IntToStr(Capabilities));
    end;

    The Call to IsVolumeSnapshotted fails with the error: "Access denied."
    But in fact, each of the calls which the app has been designed to illustrate fails, in one way or another.

    In the original code, this would not compile:
        if ( not CopyFile( PAnsiChar( Path ), PAnsiChar( DestPath ), True ) ) then
        begin
          begin
            ErrorMsg := 'File backup failed: ' + SysErrorMessage( GetLastError( ) ) + '.';
            BackupLogMemo.Lines.Add( ErrorMsg );
            ShowMessage( ErrorMsg );
          end
        else
        begin
          ErrorMsg := 'File backup OK!';
          BackupLogMemo.Lines.Add( ErrorMsg );
          ShowMessage( ErrorMsg );
        end;
    With the error:
    [DCC Error] MainForm.pas(280): E2010 Incompatible types: 'PWideChar' and 'PAnsiChar'

    on the CopyFile line.

    I replaced PAnsiChar with PWideChar, and the compiler is satisfied, but perhaps that is still incorrect.

    ReplyDelete
  2. What you show us is a classical API port error. You seems to use an old port of the API made for ansi. using post D2009 compiler, you have to revise all the API functions declaration and make sur you use the Unicode Windows API. I don't know for the VSS API, but most Windows API have two versions for each function: one ansi and one Unicode. You have to use the correct one. Unicode API functions are usually postfixed with "W" while ansi version is postfixed with "A". Having the compiler satisfied is not enough. Windows must be satisfied as well. If the compiler pass a Unicode string, then the API must expect an Unicode string as well.
    As an example of postfixing with "W" or "A", see Windows.pas unit and search for "MessageBoxW" and then try to understand how it is used. Do similar déclarations for the VSS API.

    ReplyDelete
  3. François Piette On the other hand, I found this:

    It is very complicated. Some classes, like IVssWriterImpl, require
    the use of the __thiscall calling convention, which Delphi doesn't
    know. It can be emulated, but that is not so easy, since the C++ DLL
    will be doing the calls. The other way around is a lot easier, but I
    don't know yet how to do this.
    --
    Rudy Velthuis (TeamB) http://www.teamb.com

    So perhaps I shall pass. I am not in need of a major diversion just now.

    ReplyDelete

Post a Comment