Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unicode strings and Binary Registry entires.

Posted on 2005-05-17
4
Medium Priority
?
634 Views
Last Modified: 2010-04-05
Hello,

I would like to be able to edit some registry entries. The entries are stored as binary. They are actually unicode strings

i.e. 77 00
for w

I would like to read in the value convert to ansi string make change convert back to unicode and write it back to the registry. I am not sure of the best way or easiest way to make the conversion...  the strings would be of variable length, null terminated 00 00.

Thanks for any help.
Kent
0
Comment
Question by:KentDRuddick
4 Comments
 
LVL 11

Assisted Solution

by:robert_marquardt
robert_marquardt earned 500 total points
ID: 14020070
Try the Jedi Code Library (http://jcl.sf.net). I have written the JclRegistry functions and they accept REG_BINARY for reading Unicode strings.
For writing you explicitly specify the type.
The transformation is simple. You read a WideString, assign it to a string, change it, assign it to a WideString and write it to the registry.
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 500 total points
ID: 14020091
I think you need to take a look at the unicode library and free source code

http://unicode.soft-gems.net/Tools.php

if you want to read something from the registry first though here is how you would put something into a local variable (which I guess you could then convert from unicode)

uses
  registry;

procedure TForm1.ReadRegistryKeys;
var
  FIniFile: TRegIniFile;
  sUser: String;
begin
  FIniFile := TRegIniFile.Create;
  try
    // set the root key to the entry point within the registry
    FIniFile.RootKey:=HKey_Local_Machine;
    // say you had a user key in the database somewhere under an application called "MyApp"
    sUser := FIniFile.ReadString('Software\MyApp, 'Username', '');
  finally
    // free the instance of the
    FIniFile.Free;
  end;
end;
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 14020482
try two functions below to convert from/to unicode strings


Converts Unicode string to Ansi string using specified code page.
  @param   ws       Unicode string.
  @param   codePage Code page to be used in conversion.
  @returns Converted ansi string.
}

function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
var
  l: integer;
begin
  if ws = ' then
    Result := '
  else
  begin
    l := WideCharToMultiByte(codePage,
      WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
      @ws[1], - 1, nil, 0, nil, nil);
    SetLength(Result, l - 1);
    if l > 1 then
      WideCharToMultiByte(codePage,
        WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
        @ws[1], - 1, @Result[1], l - 1, nil, nil);
  end;
end; { WideStringToString }


{:Converts Ansi string to Unicode string using specified code page.
  @param   s        Ansi string.
  @param   codePage Code page to be used in conversion.
  @returns Converted wide string.
}
function StringToWideString(const s: AnsiString; codePage: Word): WideString;
var
  l: integer;
begin
  if s = ' then
    Result := '
  else
  begin
    l := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@s[1]), - 1, nil, 0);
    SetLength(Result, l - 1);
    if l > 1 then
      MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@s[1]),
        - 1, PWideChar(@Result[1]), l - 1);
  end;
end; { StringToWideString }


http://www.swissdelphicenter.ch/torry/showcode.php?id=1692
0
 

Author Comment

by:KentDRuddick
ID: 14023427
Thank you.

Both answers can get me where I am going so I split the points. I felt the first two were best because they also addressed the registry.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question