Link to home
Start Free TrialLog in
Avatar of saar2
saar2

asked on

Binary values & strings

Hi

I need to retrieve the Outlook default profile key from the Registry and then to access it.

If I get Profile UID from HKEY_CURRENT_USER\Software\Microsoft\Windows Messaging Subsystem\Profiles\Microsoft Outlook , I get a string value.

In the Registry it is a binary value.

I need to get the binary value as a string

For example, in Regedit I see the value as :
C0 B3 74 44 91 9A D2 11 A8 CE 00 40 95 A0 5F 99 09

This binary value means À³tD‘šÒ¨Î , if I have the string, how can I have the binary value as a string? (String:='C0 B3 74 44 91 9A D2 11 A8 CE 00 40 95 A0 5F 99 09')


I hope you'll understand me.

Saar


Avatar of heathprovost
heathprovost
Flag of United States of America image

I think I can answer this, but you need to clarify more - do you want to convert the value of one of the keys in a profile to a string representation of it?  for example:
key value = C0 B3 74 44 91 9A D2 11 A8 CE 00 40 95 A0 5F 99 09

you want to get a string that represents this like
 'C0 B3 74 44 91 9A D2 11 A8 CE 00 40 95 A0 5F 99 09'?

Is this what you are trying to do?
Avatar of williams2
williams2

This must be it then..

I must warn you, that the buffer length is just a fictive value.

Function ReadBinaryKey: String;
var
  i,Len: Integer;
  Buf: PByteArray;
  Registry: TRegistry;
Begin
  Registry:= TRegistry.Create;
  Registry.RootKey:= HKEY_CURRENT_USER;
  If Registry.OpenKey('Software\Microsoft\Windows Messaging Subsystem\Profiles\Microsoft Outlook',False) then
  Begin
    Buf:= AllocMem($FFFF);
    Len:= Registry.ReadBinaryData('Profile',Buf^,$FFFF);
    Result:= '';
    For i:= 0 to Len-1 do Result:= Result+IntToHex(Buf[i],2)+' ';
    If Len>0 then Delete(Result,Length(Result),1); //Delete last space
    FreeMem(Buf,$FFFF);
  End else
    ShowMessage('Didn''t find key!');
  Registry.free;
End;

procedure TForm1.Button1Click(Sender: TObject);
var
  S: String;
begin
  S:= ReadBinaryKey;
  If S<>'' then ShowMessage(S);
end;


Regards,
Williams
Avatar of saar2

ASKER

williams2, I forgot to say I use Delphi 1. There is no Tregistry component.

Saar
ASKER CERTIFIED SOLUTION
Avatar of williams2
williams2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saar2

ASKER

When I compile this Unit I get an error saying :
"Error in module Unit1: Call to RegisterClasses is missing or incorrect"

What does it mean?

Saar
I'm not sure, but to replace the TMyReg class type:

  TMyReg = class(TPersistent)
  private
    CurrentKey: HKEY;
    function GetDataInfo(const ValueName: string; var Value: TRegDataInfo): Boolean;
  public
    CurrentPath: String;
    Root: HKEY;
    Constructor Create;
    Destructor Destroy; override;
    Function OpenKey(const Key: String): Boolean;
    function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
    function GetData(const Name: string; Buffer: Pointer;
      BufSize: Integer; var RegData: TRegDataType): Integer;
    Procedure CloseKey;
  End;

and replace this too:

Constructor TMyReg.Create;
Begin
  inherited create;
  Root:= HKEY_CLASSES_ROOT;
End;

Another thing:

Try debug the code, and tell me EXACTLY at witch codeline the error is being raised!

BTW: Why don't you upgrade your Delphi to a newer version? There's too many things that is not registrated, even Delphi 2 can provide 5 times more tah version 1.

Regards,
Williams
Avatar of saar2

ASKER

My school decided to buy Delphi 4.0 .
I'll get it next week and try again.

Saar
Good for you :-)