Reputation: 636
Whenever i use MessageBox function, i am getting first chance exception. My messagebox is like this.
MessageBox(NULL, (LPCWSTR)L"testing", (LPCWSTR)L"SOFTSAFETY", MB_OKCANCEL | MB_ICONWARNING);
If i debug, i am getting this
First-chance exception at 0x76267A24 (user32.dll) in Thread Message BOX.exe: 0xC0000005: Access violation reading location 0x001629D0.
First-chance exception at 0x76267A24 (user32.dll) in Thread Message BOX.exe: 0xC0000005: Access violation reading location 0x001629D0.
First-chance exception at 0x76267A24 (user32.dll) in Thread Message BOX.exe: 0xC0000005: Access violation reading location 0x001629D0.
First-chance exception at 0x76267A24 (user32.dll) in Thread Message BOX.exe: 0xC0000005: Access violation reading location 0x001629D0.
How can i remove those exceptions? My program is not suspended because of this exceptions, its just displaying in the output window. So can i neglect these. Please guide me.
Upvotes: 0
Views: 435
Reputation: 158
Perhaps taking a look on the MSDN would help you? The MessageBox function has the following prototype:
int WINAPI MessageBox(
_In_opt_ HWND hWnd,
_In_opt_ LPCTSTR lpText,
_In_opt_ LPCTSTR lpCaption,
_In_ UINT uType
);
LPCTSTR
is a pointer to TCHAR
, and that is not necessarily a wide character. In wtypes.h
, you will find:
const TCHAR *LPCTSTR
and TCHAR
can be wchar_t
or a char
, depending on your project's settings. Your problem is almost certainly that you forced (via a cast) wide chars where regular ones were expected.
You can try using the _T()
macro, to generate regular or wide string literals according to your project's configuration.
Upvotes: 1