?
Solved

Registry - Binary Data (part 2)

Posted on 2004-10-14
7
Medium Priority
?
628 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
[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
7 Comments
 
LVL 23

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 2000 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
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.

 

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 34

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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

719 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