Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

How to convert binary data to string

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

0
rsivam
Asked:
rsivam
1 Solution
 
Ray_AdamsCommented:
This is just UNICODE string. Use
var
  data:array[0..255] of WideChar;
as a buffer for reading.
0
 
steve_hskCommented:
Hi Rsivam ...

If you want the recent docs info, then there may be a better approach ... I thought there was a shell api function  like this one ...

procedure DoStuff(const Filename: string);
begin
  SHAddToRecentDocs(SHARD_PATH, @Filename[1]);
end;

I think this what your currently trying to do, although the output isn't completely clean :

procedure TForm1.Button1Click(Sender: TObject);
VAR Registry : TRegistry;
    Buffer   : array[1..255] of char;
    isize : Integer;
    sOutput : String;
    iCharCount : Integer;
begin
    Registry := TRegistry.Create;

    Registry.RootKey := HKEY_CURRENT_USER;
    Registry.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\Folder',False);
    iSize := sizeof(Buffer);
    Registry.ReadBinaryData('a', Buffer, isize);
    Registry.Free;

    sOutput := '';
    For iCharCount := 0 To iSize do
    begin
        IF Buffer[iCharCount] <> #0 THEN
        begin
            sOutput := sOutput + Buffer[iCharCount];
        end;
    end;
    // NOTE >> Need a memo and a button on a form :
    Memo1.Lines.Add(sOutput);
end;

Here are 2 good examples of bin to string conversion :

http://www.latiumsoftware.com/en/delphi/00004.php

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10111505.html

Hope this helps,
Steve
0
 
merry_princeCommented:
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.ReadBinaryData('PASSWD', Buffer, isize);
   Registry.Free;
   Buffer[isize] := #0;
   ShowMessage(buffer);
end;
0
 
CleanupPingCommented:
rsivam:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
snehanshuCommented:
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:

Answered by: steve_hsk

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now