Sign in to follow this  
core-nuts

Beginner Windows Question

Recommended Posts

core-nuts    132
I have recently began my journey to learn how to program under the Windows API. I was doing alright under Dev-C++, but I have recently switched over to Visual Studio 2005. I am now have some problems just compiling the simplest of programs I was using as a test.
// Windowstest.cpp
//

#include "stdafx.h"
#include <windows.h>

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  MessageBox(NULL, "Hello World!", "Message", MB_OK);
  return 0;
}


And I get these errors: Windowstest.cpp(9) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [13]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Now, I can cast the two strings to LPCWSTR and it will compile fine but print out jiberish in the actual program. So I guess I just have no idea why it is not working as is...if it is something specific to Visual Studio or what...I have tried to search for an answer but can't seem to find anything useful, so any advice would be GREATLY appreciated... Thanks!

Share this post


Link to post
Share on other sites
Endurion    5411
VS 2005 defaults to Unicode, therefor you have to append the L-macro to simple text strings:

MessageBox( NULL, L"Hello World!", L"Message", MB_OK );

Either that or you turn off Unicode in your project setting.

Share this post


Link to post
Share on other sites
core-nuts    132
Yea thats what I read on another post...I ended up just turning unicode off for now. But I was curious if there was any benefit to using unicode, this is the first I've heard of it and if I would be better off using it from now on, I will do so.

Anyways, thanks for the reply.

Share this post


Link to post
Share on other sites
vrok137    241
I hope I am not too late to reply...

Unicode is basically what the name says, Universal Character codes. Unicode has letters ranging from the Latin to Arabic alphabet. So pratically every letter/symbol/number known to man is defined somewhere in Unicode. The only thing is, Unicode has up to 20,000 values. That is why you have to use "L". Unlike 8 bit ASCII characters, Unicode uses 2 bytes to denote each character in its massive library. The downfall is that not a lot of programmers use unicode, so consequently Unicode is still an unheard word to some. Was that of any help?

Good question core-nuts [smile]. rating++

Share this post


Link to post
Share on other sites
core-nuts    132
Yes! Very helpful. Thank you so much.

Though I'm stuck on something else now, one of these days I'll be able to actually START coding under Visual Studio...ugghhh

Share this post


Link to post
Share on other sites

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