Sign in to follow this  

Win32 Prob

This topic is 4206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this