EnumResourceNames + RT_STRING
Friday, May 4th, 2012It sounds pretty straightforward to enumerate the resources  in a file. But it turned out to be rather a lot of work (and waste of time), since the MS doesn’t tell you, that it doesn’t enumerate the strings, but blocks of strings in a binary format that you have to process yourself.
Here’s how to do it:
BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam) { switch ((int)lpszType) { case RT_STRING: { HRSRC hRes = FindResourceEx(hModule, RT_STRING, MAKEINTRESOURCE(lpszName), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); if (hRes) { HGLOBAL hGlo = LoadResource(hModule, hRes); LPCWSTR lpStr = (LPCWSTR)LockResource(hGlo); DWORD dwsize = SizeofResource(hModule, hRes); long count=0; for (int i=0; i < (int)dwsize; i++) { count++; if (count>=16) break; if (lpStr[i]) { WORD *pString = lpStr+i+1; long lString = lpStr[i]; //Process string here i += lpStr[i]; } } } } break; } return(TRUE); } EnumResourceNames(hModule, RT_STRING, &EnumResNameProc, NULL);