• Status: Solved
• Priority: Medium
• Security: Public
• Views: 290

How to convert binary data to string

Registry.RootKey := HKEY_CURRENT_USER;
Registry.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\Folder',False)
How to convert binary data to string.

0
rsivam
1 Solution

Commented:
Sort of depends on what precisely you want to do with the string (display it? store it? manipulate it?) and how long that string is (using the shortstring 'string' type, youhave a maximum of 255 characters.)

so you could try
var s : string; i : integer;

s := '';
while i > 0 do
s := char(buffer[i]) + s; {assuming buffer is an array of byte}

which may give you a string of non-ASCII characters

or
...
while i > 0 do
s := hex2(buffer[i]) + s; {assuming buffer is an array of byte}

and hex2 is something like

function hex2(b : byte) : string[2];
const
hexchars : array[0..15] of char = ('0','1','2',
'3','4','5',
'6','7','8',
'9','A','B',
'C','D','E','F');
begin
hex2 := hexchars[b div 16] + hexchars[b mod 16];
end;

...it all really depends on what you mean!

...Bill
0

Commented:
Carry out below method, you can use buffer var as string.

var Registry: TRegistry;
Buffer   : array[1..255] of char;
isize : Integer;
begin
Registry := TRegistry.Create;

Registry.RootKey := HKEY_LOCAL_MACHINE;
Registry.OpenKey('\SOFTWARE\Prn\DEMO2',False);
iSize := sizeof(Buffer);
Registry.Free;
Buffer[isize] := #0;
ShowMessage(buffer);
end;
0

Commented:
Not neccessarily, I fear merry_prince!

This is one of the downfalls of ASCIIZ strings - they don't take to internal-nulls very well.

The returned series of bytes MAY contain an internal null, so your showmessage would show a string terminated at that point. Remember, a readbinarydata gets a series of bytes that can be ANY value - such as a serial number encoded as a straight binary.

...Bill
0

Author Commented:
Dear Mr.millious

Thank u for your detailed mail.
My aim is tio find the current open dir in explorer.

When i  read the binary data stored in
\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\Folder',

it returns the value 0 for all  values stored in the folder.

pls. give your  idea reg. How to get the current open
directory.

0

Commented:
rsivam:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Commented:
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is: