-
October 11th, 2009, 01:44 PM
#1
MessageBox() variables as parameters
I am having some embarrassing problems that I can't get my head around. I expect many people here will be able to help with this one.
I want a message box to output a variables content, but I am running into difficulties. My code basically goes something like this:
Code:
int iErrorCode = GetLastError();
char szErrorText[256];
ZeroMemory(szErrorText, sizeof(szErrorText));
sprintf(szErrorText, "Error Code Returned: %d", iErrorCode);
int iMessageReturn = MessageBox(NULL,
szErrorText,
L"Title of the box!",
MB_ICONERROR | MB_RETRYCANCEL);
I think this is something to do with the unicode setting but I don't know how to rectify. Can someone please help by telling me how I can convert the char variable into a LPCWSTR that the MessageBox() function won't moan about?
Thanks,
Tom
-
October 11th, 2009, 02:08 PM
#2
Re: MessageBox() variables as parameters
Code:
int iErrorCode = GetLastError();
TCHAR szErrorText[256];
ZeroMemory(szErrorText, sizeof(szErrorText));
stprintf(szErrorText, TEXT("Error Code Returned: %d"), iErrorCode);
int iMessageReturn = MessageBox(NULL,
szErrorText,
TEXT("Title of the box!"),
MB_ICONERROR | MB_RETRYCANCEL);
Best regards,
Igor
-
October 11th, 2009, 02:14 PM
#3
Re: MessageBox() variables as parameters
Originally Posted by Igor Vartanov
Code:
int iErrorCode = GetLastError();
TCHAR szErrorText[256];
ZeroMemory(szErrorText, sizeof(szErrorText));
stprintf(szErrorText, TEXT("Error Code Returned: %d"), iErrorCode);
int iMessageReturn = MessageBox(NULL,
szErrorText,
TEXT("Title of the box!"),
MB_ICONERROR | MB_RETRYCANCEL);
Awesome, thanks for the response.
What header do I need to include for stprintf() support?
Thanks again
EDIT: Appears to be working with _stprintf(). Presumably just a typo in the previous post!?
Last edited by AnotherMuggle; October 11th, 2009 at 02:23 PM.
-
October 12th, 2009, 03:39 AM
#4
Re: MessageBox() variables as parameters
_stprintf() and stprintf() are the same.
Regards,
Ramkrishna Pawar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|