reading messages from message table

Sometimes data is also stored as message instead of resources.
the easiest way to read this is as below:


ofstream myfile;
myfile.open ("example.txt");
HMODULE handle = LoadLibrary("AgentRes.dll"); // dll for reading the file
DWORD err=::GetLastError();
for(int i=0;i<10000;i++)
{
LPTSTR    lpMsgBuffer=NULL;
DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
handle,
i, // number of the corresponding message
// you can retrieve this either by using resource hunter or other strings.exe utility
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuffer,
0,
NULL);
if(lpMsgBuffer!= NULL)
{
char *str=lpMsgBuffer;
string sstr=str;
if(sstr.length()>0)
{
myfile<<"number "<<i<<" string "<<sstr<<endl; // write the string to a file
//MessageBox(NULL, "message read", " long",MB_OK);
}
}
int j =0;
}
myfile.close();

Leave a Reply

Your email address will not be published. Required fields are marked *