C code - check my syntax for me


I've come up with the code below. Within context it does exactly what I want it to do. I'm paranoid its gonna give me a memory error somehow - specifically the first line of Main.

Validate please!

JCHAR cTempChar = {0 };

pVoid = (LPVOID*)_J("X");
memcpy((void *) &cTempChar,(const void *) pVoid, sizeof(cTempChar));
Thanks Craig

I need to go via pVoid as I'm getting the original value from JDB_GetTableColValue (which you helped me out in a previous thread).

In the code above I'm try, to override the value of pVoid before I use it in JDB_AssignColumnValue.

So the line that worries me is:
pVoid = (LPVOID*)_J("X");

In my head I read it as:
"X" is a unicode string. Using '*', get me a pointer to it but return it as a pointer of type (LPVOID). This way I can assign it to the pointer variable pVoid.

It seams to work and don't give me any problems but still I would like someone to cast a eye over it.

This line I just use for debugging so I can see whats in pVoid.
memcpy((void *) &cTempChar,(const void *) pVoid, sizeof(cTempChar));

Thanks Craig.

In my code pVoid gets set by JDB_GetTableColValue (something you prev helped me out on).
Eventually, pVoid gets used in JDB_AssignColumnValue.

Here I'm just trying to override the pVoid value (given that the column has a DD type of EDSP)

So the line that worries me is:
pVoid = (LPVOID*)_J("X");
In my head it reads: Return me a pointer to "X". Instead of a pointer to a string, cast it into a pointer of type (LPVOID) so it can be assigned to variable pVoid

That sound right?
GetTableColValue returns a pointer to the column value. To be safe, you should copy the value to a local variable of the proper type.
Simplified code:


memcpy(&cEDSP, GetTableColValue(...), sizeof(JCHAR));

if you want to change that value, and set the column value:

cEDSP = _J('X');
AssignColumnValue(..., (LPVOID)&cEDSP);