Win32 Prob

Started by
5 comments, last by yadango 17 years, 10 months ago
I've been reading forgers win32 tutorials but when i compile them the message appear as a string of squares. What is the problem? here the chapter 1 code:
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
				   LPSTR lpCmdLine, int nCmdShow)
{
	MessageBox(NULL, LPCWSTR("Goodbye, cruel world!"), LPCWSTR("Note"), MB_OK);
	return 0;
};
i wrapped the string in LPCWSTR(...) to prevent type casting errors btw i'm using msvc 8 thanks jason
Advertisement
Quote:Original post by JasonL220
i wrapped the string in LPCWSTR(...) to prevent type casting errors


That won't work. You're casting the pointer to the string to a different type (LPCWSTR), but the string itself is still ANSI. You need to call MessageBox like this:
MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK);
This tells the compiler to actually generate a wide-character string. It would probably be even better to use one of the TCHAR macros rather than 'L', but I've never used those myself.
Casting to LPCWSTR doesn't solve your problem. You can either go to your project settings and change the character set from Unicode to Multi-Byte and remove the casts; change the LPCWSTR casts to L prefixes (e.g. L"Note") or change the LPCWSTR casts to _T macro calls (e.g. _T("Note")) and include tchar.h.
You can't just cast a pointer to ansi string to a pointer to wide character string. You should either use wide character string literals (L"your text here"), literals which automatically match the settings of your project (TEXT("your text here")), set your project not to use unicode and stick with ansi strings or convert from ansi to wide character at runtime (i.e. mbstowcs).

Σnigma
in the second chapter i get this warning

main.cpp(74) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data

the code is return msg.wParam;

is this a prob?

thanks for clearing that up
You can no longer return the wParam of the message because the two no longer are the same size. I just return 0 or -1 depending on if there is an error.
just make that (int)msg.wParam; and you will be fine. it's only really important though if you use PostQuitMessage with anything else other than 0.

This topic is closed to new replies.

Advertisement