WE-LogoWESTPHAL ELECTRONIC

www.westphal-electronic.com


Hints concerning use of API (Application Program Interface)
for the ZRANDOM generators

General


Advantages


Demo source code for a DLL function call in Delphi



unit Unit1_CallZran;  // Windows API (Application Program Interface)
// This file calls the function StartZrandom in Zran.dll
// in order to generate 20000 true random bits on demand.
// This file is a DELPHI Unit used by the DELPHI Project CallZran.dpr
// Zran.dll can also be used by C++ or Visual Basic!

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;

implementation

var
returnvalue,i : longint;
randombits : array[0..19999] of longint;
s,allbits : string;

function StartZrandom(baseaddress,mode:longint; filename_bin,filename_log:PChar;
writefiles:longint; var randombits : array of longint) : longint;
stdcall; external 'Zran.dll';

begin

{
The function parameters have following meanings:
1. Base address of the ISA-Slot-Card (default: $210).
   The "$" sign indicates that 210 is a hex number.
   (Not necessary for USB version.)
2. Generation mode (0: physical, 1: XOR)
3. Binary file name
4. Protocol file name
5. Write files (0: No, 1: Yes)
6. Array [0..19999] of generated True Random Bits (longint)
Possible function results:
return value = 0 -> No Error
return value > 0 -> Error described in the protocol file
}

// ---------------- Start ZRANDOM generator ----------------------------------------------
returnvalue:=StartZrandom($210,0,'ZBITS.BIN','ZBITS.LOG',1,randombits);
// -------------------------------------------------------------------------------------------------------

s:=Format('%d',[returnvalue]);
ShowMessage('Return value = '+s);

// Show first 1000 True Random Bits:
allbits:='';
for i:=0 to 999 do
begin
 s:=Format('%d',[randombits[i]]);
 allbits:=allbits+s;
 if ((i+1) mod 80)=0 then allbits:=allbits+#13
end;
ShowMessage(allbits);

end.


The function call is marked red.
The result of this demo program is a window containing the first 1000 (of 20000 generated) true random bits.

Here you will find a text file with the demo program.



Links concerning use of DLL functions in Delphi, C++, Visial Basic

About Delphi Programming
http://delphi.about.com/

Dynamic Link Libraries and Delphi
http://delphi.about.com/library/weekly/aa041100a.htm

Visual Basic source code of DLL use
http://delphi.about.com/gi/dynamic/offsite.htm?site=http://www.avdf.com/aug95/samp1%5Fdll3.html

About C/C++
http://cplus.about.com/

About Visual Basic
http://visualbasic.about.com/

Programmers Heaven
http://www.programmersheaven.com/

EXE vs. DLL - Which one?
http://www.visualcadd.org/articles/api/api2.html#vcsetup



Back to start page


Copyright WESTPHAL ELECTRONIC
Webmaster: info@westphal-electronic.com
Last update: 29/08/2003