WE-LogoWESTPHAL ELECTRONIC

www.westphal-electronic.com


Hints concerning use of API (Application Program Interface)
for the ZRANDOM USB generator
(DLL function call)

General

Advantages

Demo source code for a DLL function call in Delphi

unit Unit1_CallZranUSB;  // Windows API (Application Program Interface)
// This file calls the function StartZrandomUSB in ZranUSB.dll
// in order to generate 20000 true random bits on demand.
// This file is a DELPHI Unit used by the DELPHI Project CallZranUSB.dpr
// ZranUSB.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 StartZrandomUSB(mode:longint; filename_bin,filename_log:PChar;
writefiles:longint; var randombits : array of longint) : longint;
stdcall; external 'ZranUSB.dll';

begin

{
The function parameters have following meanings:
1. Generation mode (0: physical, 1: XOR)
2. Binary file name
3. Protocol file name
4. Write files (0: No, 1: Yes)
5. 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:=StartZrandomUSB(1,'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.
 

(The DLL is not tested for C++ or VB, no support for C++ or VB)


Back to start page


Copyright WESTPHAL ELECTRONIC
Webmaster: info@westphal-electronic.com
Last update: 09/04/2005