Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok I am kind of confused, I am trying to create a mini dump of my process. Therefore I am calling the code like this.

C++
HANDLE hFile =  CreateFile((LPCWSTR)"C:\\Test\\Reader4.dmp",                // name of the write
                       GENERIC_WRITE,          // open for writing
                       0,                      // do not share
                       NULL,                   // default security
                       CREATE_ALWAYS,             // create new file only
                       FILE_ATTRIBUTE_NORMAL,  // normal file
                       NULL);                  // no attr. template

	std::cout<< "Error:" << GetLastError() << std::endl;

	   if ( ( hFile != NULL ) && ( hFile != INVALID_HANDLE_VALUE ) )
	   {
			if (!MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),hFile, MiniDumpNormal,0,0,0))
			{
				std::cout<< "Mini Dump Error:" << GetLastError() << std::endl;
			}
	   }
	CloseHandle(hFile);


Everything checks out! GetLastError always returns 0. I finish my current process, however I never can find a dmp file like ever.
Posted

Quote:
HANDLE hFile = CreateFile((LPCWSTR)"C:\\Test\\Reader4.dmp",
That's not the correct way to pass a wide string to the function. Change to:
HANDLE hFile =  CreateFile(L"C:\\Test\\Reader4.dmp",



(The OS interpreted the ASCII string as it was a WIDE one and you should be able to find a file named "㩃呜獥屴敒摡牥⸴浤p牅潲㩲", that is the dump :-D, in the project folder)
 
Share this answer
 
Solution 1 is accurate, you were passing the string in a wrong way.

But don't call MiniDumpWriteDump on the current process.

Let's say that you implement an exception handler.
when handler is called your application might be in an unstable state.
What if you ran out of stack space, or you experience corrupted memory.
You might be unable to write the minidump.

You should preferably spawn a new process that calls MiniDumpWriteDump on the first process.
 
Share this answer
 
Comments
CdnSecurityEngineer 31-Jan-14 10:31am    
That's more or less what I was doing. However the code I posted was just debugging code to ensure that everything was functioning correctly. Once I had the bugs worked out I changed it to dump the correct process that I wanted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900