Solved

Registry - Binary Data (part 2)

Posted on 2004-10-14
7
621 Views
Last Modified: 2012-05-05
Might seem like an odd thing to do but...

I have loaded an array of bytes with binary data from the registry (this works perfectly so far)

now what i want to do is move the contents of the array into a record.  I have used Copymemory and even Movememory but it doesn't work. I am using Delphi 4 Professional - if that helps.

example:

Type
      TCardValues = packed record
       Deck: integer;
       Name: string[200];
       Card: Integer;
       Pos  : Integer;
       Picked : Boolean;
end;

var

    Card : TCardValues;

{rest of program}


I use this procedure to load the information back from the registry

procedure Load;
var
Buffer: Array of bytes
begin
 
   {call routine to get binary data from registry - Buffer will then contain returned data}
   

I have tried:  movememory(@card, buf, length(buf));  and it seems to work but then the program displays a runtime error 216 on exit
If i use movememory(@card, buf, sizeof(buf)); the error stops but i don't get the entire information back into the card record
and movememory(@card, buf[1], sizeof(buf)); or movememory(@card, buf[1], length(buf));  does not even compile


end;

0
Comment
Question by:mi6agent
7 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12307589
I assume that you're using RegReadBinary from the previous question to fill the buffer....

The RegReadBinary result is the size of the buffer so try using it directly....

Var BufSize:  cardinal;

BufSize := RegReadBinary(......

movememory(@card, buf, BufSize);
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12307622
Have you tried:

Move(Buf,Card,sizeof(Card));

0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 500 total points
ID: 12307683
After some testing, I discovered that either of these should work for you:

  move(buf[0],card,sizeof(card));
  movememory(@card,@buf[0],sizeof(card));

Referencing the first element of the array is the "trick".
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mi6agent
ID: 12307924
>I assume that you're using RegReadBinary from the previous question to fill the buffer....

Yes, i am using that routine to grab the information.

Tried movememory(@card, buf, BufSize);  - still no luck


>Have you tried: Move(Buf,Card,sizeof(Card));

Yep, didn't work either

0
 

Author Comment

by:mi6agent
ID: 12308080
Thanks LRHGuy - i'll give them both a try out and get back to you asap
0
 
LVL 33

Expert Comment

by:Slick812
ID: 12311039
not sure about all of the code you use? But To me, it seems like you may be doing an extra Step that I would skip, , , It seems like you use some sort of "Buffer" as an array of Byte to get the reg data, and then you want to transfer this bufffer to a TCardValues . . .  I would just put the data into the TCardValues in the first Reg Read operation and then I would not need a buffer, maybe something like this -

var
    Card : TCardValues;

ReadRegBinary(aKey, regName, Card, SizeOf(Card)):


this is untested, from my head, but my suggestion is to skip the Buffer transfer. .
0
 

Author Comment

by:mi6agent
ID: 12317437
Thanks to everyone for suggestions.

LRHGuy - i tested out your code and got it to work with no problem.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now