Category: MSDN

Getting the parent id of a process

Below is the code to return the parent id of a process, given a process id. This can be helpful in circumstances when we have to scan all the running processes to find out the spawned processes from another process. [code language=”cpp”] // change this method signature according to your requirements BOOL GetParentPID( DWORD dwParentId,

Continue Reading →

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

Continue Reading →

Windows debugging using windbg

Sometimes or most times when you get a crash dump from your customer, its always good to know how to reproduce the crash and point out where the actual crash happens. Today I was debugging some bug with my lead, I found this very useful: Here are the steps: First of all open the windows

Continue Reading →

Detecting memory leaks in VC++

One of the simplest ways to detect a leak in your code would be to use debugCRT. Simple usage: a. Create you project in visual studio b. run the project in debug mode, then only you will find the memory leak dumps int main() { _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF); //below call will break where the leak

Continue Reading →

comparing two systemtime variables using filetime in vc++

lets take a look at how to compare two systemtime variables but using Filetime to do so. We make use of the utility method CompareFiletime to do this. 1) store the systemtime in a variable 2) convert it into filetime. Use this method SystemTimeToFileTime(&systemtime1, &filetime1) SystemTimeToFileTime(&systemtime2, &filetime2) 3) Compare the filetimes using the method CompareFileTime(&filetime1,

Continue Reading →