How to use WriteBinaryData (Views: 712)
Problem/Question/Abstract: Can someone explain exactly how to use WriteBinaryData? I've tried several different ways but the output is never what it should be. Answer: uses Registry var RG: Registry; PrinterName: string; {This is just a value} Buffer: array[0..1024] of Char; {This is the Binary data} J, K: Integer; dFiles: array[0..5] of string; {The string data that will be converted to Binary Data} S, S2: string; sChar: Char; procedure Whatever; begin {Reset buffer} for i := 0 to 1024 do buffer[i] := #00; {Reset S} S := ''; dfiles[0]: 'MyPrint.Drv'; dfiles[1]: 'MyPrint.DLL'; dfiles[2]: 'Myunit.DLL'; dfiles[3]: 'MyPrint.HLP'; dfiles[4]: 'MyPrnt2.DLL'; dfiles[5]: 'MyPrnt3.DLL'; {Copy all items into one string seperated by a NULL ##00} for J := 0 to 5 do begin S := S + dFiles[k] + #00; {Copy strings to 1 string and add a #00} K := Length(S); {K function is to store the string length} end; {Convert String to char array called buffer} for J := 1 to K do begin S2 := Copy(S, J, 1); {Copy 1 char to string S2} sChar := S2[1]; {Copy S2 to sChar} buffer[J - 1] := sChar; {Copy sChar to buffer} end; {The char array MUST end with 2 NULLS} Buffer[K + 1] := #00; Printername := 'MyPrinter'; rg := TRegistry.create; rg.rootkey := hkey_local_machine; rg.Openkey('System\CurrentControlSet\Control\Print\Environments\Windows4.0\Drivers\' + PrinterName, true); rg.writebinarydata('Dependent Files', buffer, K + 1); rg.Closekey; end; |