Einzelnen Beitrag anzeigen

Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#7

How to use the MSLDBUSR.DLL to analyse the Access LDB file.

  Alt 17. Jan 2006, 15:01
Hello,

I'll post this for users searching for a way to interface with MSLDBUSR.DLL with Delphi.
The code is copied from the opensource software "Opus Direct Access" which is a
Plug-in Access/Jet database driver for Borland Delphi and C++Builder (BDE replacement)
In this driver there is a piece of code to analyse the Access LDB file.

Opus Direct Access


Delphi-Quellcode:
unit OpDAOUsers;


interface

const
  OptAllUsers = $1;
  OptLoggedUsers = $2;
  OptCorruptUsers = $4;
  OptUserCount = $8;
  OptUserAuthor = $b0b;

function GetUsers( const _LDBFileName: string; _opt: integer;
    out _users: array of string ): integer;

function GetError( _result: integer ): string;


implementation
uses
  ActiveX, Windows, SysUtils, Variants; //Variants for later delphi versions

const
  DLLName = 'MSLDBUSR.DLL';

function LDBUser_GetUsers( lpszUserBufferArray: PSafeArray; const lpszFilename: TBStr;
    nOptions: longint ): longint; stdcall;
  external DLLName;

function LDBUser_GetError( nErrorNo: longint ): TBStr; stdcall;
  external DLLName;


function GetUsers( const _LDBFileName: string; _opt: integer;
    out _users: array of string ): integer;
  var
    pfn: TBStr;
    usr: variant;
    i: integer;
    p: ^pChar;
  begin
    pfn:= SysAllocStringByteLen( nil, Length(_LDBFileName) + 1 );
    try
      StrCopy( pChar(pfn), pChar(_LDBFileName) );
      usr:= VarArrayCreate( [Low(_users), High(_users)], varOleStr );
      result:= LDBUser_GetUsers( @TVarData(usr).vArray, pfn, _opt );
      if result > 0 then begin
        p:= VarArrayLock( usr );
        try
          for i:= 0 to result - 1 do begin
            _users[i]:= StrPas( p^ );
            Inc( p );
          end;
        finally
          VarArrayUnlock( usr );
        end;
      end {if ok};
    finally
      SysFreeString( pfn );
    end;
  end {GetUsers};


function GetError( _result: integer ): string;
  var
    perr: TBStr;
  begin
    perr:= LDBUser_GetError( _result );
    try
      result:= StrPas( pChar(perr) );
    finally
      SysFreeString( perr );
    end;
  end {GetError};

end.

Here is how to call the LDBUser_GetUsers API function:

Delphi-Quellcode:
implementation

uses OpDAOUsers;

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
Var CUsers : Integer;
    psFilename : String;
    lstUsers: array of string;
begin
  SetLength(lstUsers, 20);
  //set the max on 20. increase if needed, otherwise error !!!

  psFilename:='C:\accessdatabase.mdb';
  CUsers:=GetUsers(psFilename,1,lstUsers);
  Showmessage(lstUsers[0]);
  //loop here to see all the users....
end;
Greetings,

Delphi Lover.
Rob
  Mit Zitat antworten Zitat