Click to See Complete Forum and Search --> : Converting from DWORD to LPCSTR...
YourSurrogateGod
February 25th, 2005, 06:52 PM
Using .NET. I to create a window handle, but for some reason it won't work, so I figured that I might try to get at the error and have it displayed to me when something goes wrong. Which is why I stumbled on GetLastError(), I would like to use in the MessageBox method. However, I can't convert a DWORD to a LPCSTR easily (as shown below.) I tried to cast it as char * , but was not succesful. Any ideas? I looked in the FAQs, but didn't find the answer (and if I missed it, prove me wrong.)
if(!hwnd)
{
MessageBox(NULL, "The window handle could not be created.\nThe error is: ",
"ERROR: No creation", MB_ICONERROR);
MessageBox(NULL, GetLastError(), "ERROR: No creation", MB_ICONERROR);
return 0;
}
Mick
February 25th, 2005, 07:05 PM
Format the error code into a string. If you want the text then call FormatMessage(...)
Example FormatMessage(...)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/retrieving_the_last_error_code.asp
YourSurrogateGod
February 25th, 2005, 07:21 PM
Format the error code into a string. If you want the text then call FormatMessage(...)
Example FormatMessage(...)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/retrieving_the_last_error_code.asp
What should the LPTSTR input be? When I have the if-statement that is... I'm guessing that it's the name of the method whose error I would like to get.
Mick
February 25th, 2005, 07:30 PM
Whatever you want it to be. You provide the error text and format it along with the error code and or text. Look at the link.
GetLastError(...) returns the last error that occured on the thread. Win32 calls set the last error via SetLastError(...) internally if an error occurs.
BTW: what API are you calling to create the hwnd? CreateWindow(...) what? Some API's return specific error codes others use SetLastError(...) to provide extended error information and return a NULL [mostly when returning handles]
YourSurrogateGod
February 25th, 2005, 07:35 PM
I'm using CreateWindowEx. I started messing around with the original file (it was a DirectX tutorial that I downloaded) and broke something :rolleyes:, now I want to figure out what exactly. I've attached the entire source file, just in case...
YourSurrogateGod
February 25th, 2005, 09:13 PM
Found the problem. All of the methods for creating and registering were fine. The problem was with the fact that I didn't use "{}" in my window procedure, that brought in problems with the scope.
ovidiucucu
February 26th, 2005, 07:46 AM
[...]
I looked in the FAQs, but didn't find the answer (and if I missed it, prove me wrong.)
if(!hwnd)
{
MessageBox(NULL, "The window handle could not be created.\nThe error is: ",
"ERROR: No creation", MB_ICONERROR);
MessageBox(NULL, GetLastError(), "ERROR: No creation", MB_ICONERROR);
return 0;
}
Look again at THIS FAQ (http://www.codeguru.com/forum/showthread.php?t=318721).
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.