Solved

Reading Binary Data with TRegistry

Posted on 2003-12-05
1
552 Views
Last Modified: 2010-04-05
I am currently writing an application where I need to be able to read various registry enteries without knowing their types beforehand. All the information read from the registry will be converted to a string. I have written a small bit of code that pretty much handles this, but I am having a problem with binary data. My code is as follows:

        MyReg.OpenKey(RegKey, False);
        RegType := MyReg.GetDataType(RegValue);
        if (RegType = rdString) or (RegType = rdExpandString) then sData := MyReg.ReadString(sValue);
        if RegType = rdInteger then sData := IntToStr(MyReg.ReadInteger(sValue));
        if RegType = rdBinary then
        begin
            lBinaryDataSize := MyReg.GetDataSize(sValue);
            SetLength(Buffer, lBinaryDataSize);

            MyReg.ReadBinaryData(RegValue, Buffer, SizeOf(Buffer));
       end;

"RegKey", "RegValue" are both strings whose values are predetermined earlier in the code. "Buffer" is an array of byte, which as you can see, is resized based on the size of the binary data.

The error I am recieving is when I actually come across some binary data in the registry. Despite the fact that the key type is rdBinary, I get a message that says "Invalid Data Type For 'CustomColors'" (which is the particular key I am trying to read). Any idea of what I may be doing wrong?
0
Comment
Question by:Thora_Fan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 125 total points
ID: 9881015
     
MyReg.OpenKey(RegKey, False);
        RegType := MyReg.GetDataType(RegValue);
        if (RegType = rdString) or (RegType = rdExpandString) then sData := MyReg.ReadString(sValue);
        if RegType = rdInteger then sData := IntToStr(MyReg.ReadInteger(sValue));
        if RegType = rdBinary then
        begin
            lBinaryDataSize := MyReg.GetDataSize(sValue);
            SetLength(Buffer, lBinaryDataSize);
            If lBinaryDataSize > 0 then
               MyReg.ReadBinaryData(RegValue, Buffer[0], lBinaryDataSize);
       end;

F68 ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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