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\Microso ft 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
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
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
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\Microso ft Outlook',False) then
Begin
Buf:= AllocMem($FFFF);
Len:= Registry.ReadBinaryData('P rofile',Bu f^,$FFFF);
Result:= '';
For i:= 0 to Len-1 do Result:= Result+IntToHex(Buf[i],2)+ ' ';
If Len>0 then Delete(Result,Length(Resul t),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
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
Begin
Buf:= AllocMem($FFFF);
Len:= Registry.ReadBinaryData('P
Result:= '';
For i:= 0 to Len-1 do Result:= Result+IntToHex(Buf[i],2)+
If Len>0 then Delete(Result,Length(Resul
FreeMem(Buf,$FFFF);
End else
ShowMessage('Didn''t find key!');
Registry.free;
End;
procedure TForm1.Button1Click(Sender
var
S: String;
begin
S:= ReadBinaryKey;
If S<>'' then ShowMessage(S);
end;
Regards,
Williams
ASKER
williams2, I forgot to say I use Delphi 1. There is no Tregistry component.
Saar
Saar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
"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
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
ASKER
My school decided to buy Delphi 4.0 .
I'll get it next week and try again.
Saar
I'll get it next week and try again.
Saar
Good for you :-)
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?