Solved

Registry - Binary Data (part 2)

Posted on 2004-10-14
7
619 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
Comment Utility
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
Comment Utility
Have you tried:

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

0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 500 total points
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:mi6agent
Comment Utility
>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
Comment Utility
Thanks LRHGuy - i'll give them both a try out and get back to you asap
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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
Comment Utility
Thanks to everyone for suggestions.

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

11 Experts available now in Live!

Get 1:1 Help Now