I try to embebed a custom TXT file in a win32 exe file, using codeblocks (TDM-GCC compiler) in win10 x64 machine.
Using the method answered by In silico, in similar question "buffer" variable only shows the first 3 bytes. Ex: Data.txt file contains: "HOLA MUNDO" (22 bytes checked in hex editor)
But when I show 'char* buffer' variable using MessageBox(), it only shows first three bytes of DATA.txt: ÿþH
Here is my code:
void LoadFileResource() {
char* data = NULL;
DWORD rcSize = 0;
TCHAR sResName[5] = _T("#107"); // ID from resource.h file for DATA.txt
TCHAR sRestype[8] = _T("DATAREG"); // custom typeID from .rc file for DATA.txt
HRSRC rc = ::FindResource(NULL, sResName, sRestype);
HGLOBAL rcData = ::LoadResource(NULL, rc);
rcSize = ::SizeofResource(NULL, rc); // Have value of 22, and DATA.txt have 22 bytes
data = static_cast<const char*>(::LockResource(rcData));
char* buffer = new char[rcSize+1];
::memcpy(buffer, data, rcSize);
buffer[rcSize+1] = 0; // NULL terminator, I think here is 0 for very LAST position of buffer
MessageBox(NULL, buffer, NULL, MB_OK); // Only show 3 first bytes from DATA.txt
delete[] buffer;
}
Also checked the resources compiled in final EXE file and content of DATA.txt is there "HOLA MUNDO".
What is the right way to manipulate/show content of data/buffer??
Updating: Even using another conversion mode for data, discarding 'new char[]' and 'memcpy()':
data = (char*)(::LockResource(rcData));
LPBYTE sData = (LPBYTE)data;
LPTSTR sXml = (LPTSTR)sData;
DWORD buffSize = strlen(sXml); // Result in 3, don't know why.
MessageBox(NULL, sXml, NULL, MB_OK); //Shows again only first 3 bytes of DATA.txt
Same result ÿþH.