home *** CD-ROM | disk | FTP | other *** search
- library Lock;
-
- uses
- SysUtils,
- Classes,
- SLokUtil;
-
- type TBufRec = record
- Address: Integer;
- Header: array[0..3] of Byte;
- Buffer: TBuffer;
- end;
-
- {*******************************************************************************
- * Variable : Buffer *
- ********************************************************************************
- * Purpose : This is the buffer which stores the registration information. *
- * The registration information is written into the buffer by SLock *
- * and should you want to extend this DLL to also perform other *
- * tasks, you should bear in mind that you cannot link this DLL *
- * permanently, or you will inhibit the writing of the file. *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- const
- Bufrec: TBufrec = (Header : (Ord('B'),Ord('u'),Ord('f'),Ord(':')));
-
- {*******************************************************************************
- * Procedure : GetRegInfo *
- ********************************************************************************
- * Purpose : GetRegInfo simply returns the contents of the buffer to the *
- * calling program. *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : Buffer: The registration information *
- *******************************************************************************}
- function GetRegInfo: TBuffer; stdcall;
- begin
- Result := Bufrec.Buffer;
- end; {GetRegInfo}
-
- {*******************************************************************************
- * Procedure : GetBuffAddr *
- ********************************************************************************
- * Purpose : GetBuffAddr returns the offset of the buffer in the DLL to allow *
- * SLock to access the buffer. If you change the DLL to add other *
- * functions, you should change the value returned by this function *
- * to point to the right place. NOTE that the DLL must be dynamic- *
- * ally linked to the main program or SLock will not be able to *
- * gain write access to the file. *
- * *
- * NOTE: The value returned by this can be optimised so that there *
- * is no need to search for the start of the buffer, rather it can *
- * returned directly. *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : BufferAddress: The address of the buffer *
- *******************************************************************************}
- function GetBuffAddr(dllName: Pchar): integer; stdcall;
- var
- OutputFile: File of Byte;
- b,c,d: Byte;
- Counter: integer;
- begin
- try
- AssignFile(OutputFile, dllName);
- except
- // we could not open the output file for some reason
- // so exit gracefully with an error code
- Result := 0;
- CloseFile(OutputFile);
- Exit;
- end;
-
- // reset the output file
- FileMode := 0;
- Reset(OutputFile);
-
- // get past the most of the overhead
- // ** this should be optimised to make the access fast
- // if you change the DLL!! **
- // You can use the DLLTest project to find out the start of
- // the buffer and hard code this value into the function.
- Seek(OutputFile,46670);
- Counter := 46669;
-
- // locate the right place in the file
- while not EOF(OutputFile) do
- begin
- Inc(Counter);
- Read(OutputFile,b);
- if b = Ord('B') then
- begin
- Read(OutputFile,b,c,d);
- if ((b = Ord('u')) and (c = Ord('f')) and (d = ORD(':'))) then
- begin
- // display the offset of the buffer from file start
- Result := Counter + 4;
- CloseFile(OutputFile);
- Exit;
- end
- else
- begin
- Inc(Counter,3);
- end;
- end;
- end;
-
- Result := 0;
- CloseFile(OutputFile);
- end; {GetBufferAddress}
-
- exports
- GetRegInfo index 1,
- GetBuffAddr index 2;
-
- end.
-
-