Possible Duplicate:
updating a string table with UpdateResource
I am trying to update a binaries STRING TABLE via UpdateResources, currently, my code ONLY adds a single string, but I want it to add multiple entries into the string table.
Here is my code:
HANDLE hRes = BeginUpdateResource("file.exe",TRUE);
if (hRes)
{
char * sNewString = "Line";
int iCharCount = (strlen(sNewString) + 1); //sNewString.size() + 1;
LPWSTR pUnicodeString = new WCHAR[iCharCount];
if (!pUnicodeString)
{
cout << "Error" << endl;
}
DWORD dwUnicodeCharCount = MultiByteToWideChar(CP_ACP,NULL,sNewString,-1,pUnicodeString,iCharCount);
HGLOBAL hGlob = GlobalAlloc(GHND,(dwUnicodeCharCount + 4) * sizeof(WCHAR));
LPWSTR pBufStart = (LPWSTR)GlobalLock(hGlob);
LPWSTR pBuf = pBufStart;
pBuf++;
// offset to make it string ID=1. Increment by more
// to change to a different string ID
//next 2 bytes is string length
*(pBuf++) = (WCHAR)dwUnicodeCharCount-1;
for (int i = 0; i < (int)dwUnicodeCharCount-1; i++)
{
dwUnicodeCharCount++;
}
delete pUnicodeString;
if (++dwUnicodeCharCount%1) // make sure even number
{
dwUnicodeCharCount++;
}
if(!UpdateResource(hRes,RT_STRING,MAKEINTRESOURCE(1),MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
pBufStart, dwUnicodeCharCount * sizeof(WCHAR)))
{
cout << "Function failed!" << endl;
}
GlobalUnlock(hGlob);
GlobalFree(hGlob);
EndUpdateResource(hRes,FALSE);
I attempted to edit `
char * sNewString = "Line";
to `
char * sNewString = "Line1\nLine2";
as an attempt to mimic the newline character to no avail.
Am I missing something? I looked thoroughly at http://msdn.microsoft.com/en-us/library/windows/desktop/aa381050(v=vs.85).aspx , and it doesn't look like I have missed any crucial points, and no functions are failing.