Re: LockResource returning the wrong data?!
NickP <a@a.com> wrote:
BYTE* pBytResStr = static_cast<BYTE*>(LockResource(hgl));
CString xml = pBytResStr + _T('\0');
You seem to think that "pBytResStr + _T('\0')" appends NUL character to
the end of memory buffer. It does nothing of the kind. It is actually a
no-op - it takes a pointer pBytResStr and offsets it by 0 bytes (where 0
is the ASCII code of character '\0'), so the result is pBytResStr
unchanged.
Make it
CString xml(pBytResStr, SizeofResource(NULL, hRC) );
The string "xml" appears to be fine, except it has the characters
"GIF89a" stuck on the end!!
That would be the first bytes of the next resource. You are lucky that
other resource just happens to have a 0 byte in it.
I've checked the xml document in a binary editor, and xml editor
and it does not have this on the end before compilation. I can only
presume that the LockResource is returning a byte array slightly too
large.
LockResource returns a pointer directly into your EXE's image. There is
stuff both before and after the resource proper. It is your
responsibility to access just the bytes belonging to the resource.
Any ideas? Surely I don't have to put a null terminator on the
end of the xml document.. or do I?
You don't have to. But since you didn't, don't expect it to be there.
All your surprises come from the fact that you do indeed expect, for
whatever reason, the resource to be NUL-terminated when stored in the
EXE.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925