473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can't run this simple program. Is the code to blame, or my VC++?

101 100+
Here's the simple code:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}

I chose Win32 application and chose "windows application", not "console application". Is the program at fault, or did I do something wrong when setting up my vc++ compiler for Win32?

Actually, here's the turorial I'm following:
http://www.winprog.org/tutorial/start.html

and the error I get is this:
error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'

Thanks for any help.
Jul 18 '07 #1
2 1185
zensunni
101 100+
Found the answer. I was using Unicode instead of Multibyte.
Jul 18 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Are you using tchar.h???

Then you should:
Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2.  
  3. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
  4. LPSTR lpCmdLine, int nCmdShow)
  5. {
  6. MessageBox(NULL, TEXT("Goodbye, cruel world!"), TEXT("Note"), MB_OK);
  7. return 0;
  8. }
  9.  
Do not use MessageBoxW directly.

MessageBox is a macro that resolves to MessageBoxA or MessageBoxW depending on whether Unicode is defined or not.

Read this.
Jul 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
50
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
8
by: ftjonsson | last post by:
hello, I was wondering if anyone could tips me on what I am doing wrong when writing the following code: #include <iostream> using namespace std; int main () {
6
by: charindal | last post by:
i am trying to create a program that is able to draw a housing plan. the user should be able to input the required meters then upon clicking a left,right,up, down button, the system draws a line in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.