Offsets
When adding an offset to a pointer to derive the location of another variable or entity, it is important to determine the method in which the offset was initially created.
In this example, lpKeyStruct->CacheKey[n].nOffset
is added to
lpData to arrive at the location of a Cache Key segment. This
offset was for the segment created using the ANSI C function
offsetof, which returns the number of bytes. Therefore, to arrive at
the location of Cache Key segment, cast the data structure pointer to type BYTE.
lpTemp1 = (BYTE *)lpData + lpKeyStruct->CacheKey[n].nOffset; lpTemp2 = (BYTE *)lpKey + lpKeyStruct->CacheKey[n].nOffset;
In a non-Unicode environment, lpData could have been cast to be of type CHAR * as character size is one Byte in a non-Unicode environment. In a Unicode environment, however, lpData has to be explicitly cast to be of type (JCHAR *) since size of a JCHAR is 2 bytes.