In vc++, sending WM_MDICREATE message fails so it returns null value. Anyone can help why it is getting failed
A:
There's always the GetLastError()
Win32 API function. You call it after an error occurs and then call FormatMessage()
to find out what actually happened in human-readable form.
What follows is the example for this provided by MSDN:
void ErrorExit(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
dandan78
2010-09-27 11:23:24
Sending WM_MDICREATE message in mfc class winmdi.cpp. How can i call getlasterror() function
Buna
2010-09-27 11:52:28
Since MFC is just a wrapper for Win32, I don't think there's anything special you have to do. Just call the above function immediately after the code that fails. Note that this function will display the error string in a message box and then terminate the process.
dandan78
2010-09-27 12:08:32
I didn't get solution for my problem using GetLastErrorMessage() and i have seen a warning: no shared menu for document template #128 before sending WM_MDICREATE message after that it is also getting failed. Warning and sending WM_MDICREATE message failed is happening only if i open my application when more applications are opened. Can anyone help me what is causing that warning and why this problem is happening only in particular situation?
Buna
2010-09-29 07:36:03
Google GetLastError and you'll get the MSDN article that describes the function and links to the code I posted. The point is this: if an error is occurring somwehere in your code and you have a good idea where, you can use the above function to obtain more information about what is going wrong. Of course, you have to include the above function in your own code and then call it after the error has taken place. I can't say anything about the warning you are getting. However, Google has helped me more times than I can count so there's an idea. :)
dandan78
2010-09-29 08:28:53