This question stems from my general inexperience with the C programming
language... I'll state the question first, then my example code. After I get
a record handle with DmQueryRecord, I lock it down and get a VoidPtr from
MemHandleLock. This pointer points to the start of my record in the
database, and I want to access the second field of the database, in my case,
at an offset of sizeof(WChar). But when I try to access that field by
saying: *(myPtr + myOffset), the compiler complains that it can't add
anything to a VoidPtr type. So I have to cast it as something. Depending on
how I cast it, I get different values returned to me for both the *(myPtr)
variable and the (*myPtr + myOffset) variable. Since I may have many
different types of data in my database, what's the right way to cast the
pointer to correctly access the variables? Thanks for your help. Code
follows.


I defined the properties of a record in my database like this:

#define DB_PEN_DOWN_START 0
#define DB_PEN_DOWN_SIZE sizeof(WChar)
#define DB_PEN_UP_START (DB_PEN_DOWN_START + DB_PEN_DOWN_SIZE)
#define DB_PEN_UP_SIZE sizeof(WChar)
#define DB_PENSTROKE_RECORD_SIZE (DB_PEN_DOWN_SIZE + DB_PEN_UP_SIZE)


And now I want to access the information. So I call:

VoidHand hrecord;
VoidPtr precord;
cursor = 0;
hrecord = DmQueryRecord( prevAppHackDB, cursor );
precord = MemHandleLock( hrecord );


And finally, I want to write the value of the record into two fields on my
form, using a home-made function called 'StrToField' that takes the name of
the field, the size of the data to write, and the data itself as parameters.

WChar temp;
char tempstr[10];
temp = *((WCharPtr)precord + DB_PEN_DOWN_START);  // DB_PEN_DOWN_START = 0
StrIToH(tempstr, temp);
StrToField(ControlPanelFormStartBtnField, sizeof(tempstr), tempstr); //
RETURNS THE RIGHT THING
temp = *((WCharPtr)precord + DB_PEN_UP_START); // DB_PEN_UP_START =
sizeof(WChar)
StrIToH(tempstr, temp);
StrToField(ControlPanelFormEndBtnField, sizeof(tempstr), tempstr); //
RETURNS THE WRONG THING

MemHandleUnlock(hrecord);



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to