Author: William Gerbert
Can someone explain exactly how to use WriteBinaryData? I've tried several
different ways but the output is never what it should be.
Answer:
1 uses2 Registry
3 4 var5 RG: Registry;
6 PrinterName: string; {This is just a value}7 Buffer: array[0..1024] of Char; {This is the Binary data}8 J, K: Integer;
9 dFiles: array[0..5] ofstring;
10 {The string data that will be converted to Binary Data}11 S, S2: string;
12 sChar: Char;
13 14 procedure Whatever;
15 begin16 {Reset buffer}17 for i := 0 to 1024 do18 buffer[i] := #00;
19 {Reset S}20 S := '';
21 dfiles[0]: 'MyPrint.Drv';
22 dfiles[1]: 'MyPrint.DLL';
23 dfiles[2]: 'Myunit.DLL';
24 dfiles[3]: 'MyPrint.HLP';
25 dfiles[4]: 'MyPrnt2.DLL';
26 dfiles[5]: 'MyPrnt3.DLL';
27 {Copy all items into one string seperated by a NULL ##00}28 for J := 0 to 5 do29 begin30 S := S + dFiles[k] + #00; {Copy strings to 1 string and add a #00}31 K := Length(S); {K function is to store the string length}32 end;
33 {Convert String to char array called buffer}34 for J := 1 to K do35 begin36 S2 := Copy(S, J, 1); {Copy 1 char to string S2}37 sChar := S2[1]; {Copy S2 to sChar}38 buffer[J - 1] := sChar; {Copy sChar to buffer}39 end;
40 {The char array MUST end with 2 NULLS}41 Buffer[K + 1] := #00;
42 Printername := 'MyPrinter';
43 rg := TRegistry.create;
44 rg.rootkey := hkey_local_machine;
45 46 rg.Openkey('System\CurrentControlSet\Control\Print\Environments\Windows4.0\Drivers\'
47 + PrinterName, true);
48 rg.writebinarydata('Dependent Files', buffer, K + 1);
49 rg.Closekey;
50 end;