Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error C2664 in Visual C++ Express

Status
Not open for further replies.

BlackZer0

Technical User
Mar 10, 2007
2
US
Hello, I am an absolute beginner as far as programming goes and wanted to start teaching myself in a way. I've gone out and starting looking up tutorials on how to get started and bought a beginners guide to game programming. I've started on my first program (much like the hello world program) but I keep getting error code C2664. I downloaded the platform SDK and copied bin, lib, and include files into the C++ folder. Here is my source:

#include <windows.h>


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
MessageBox(NULL, "Starting off small",
"BlackZer0", MB_OK);
}

And now here is the error I keep recieving in the debug box:

------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\pat eason\my documents\visual studio 2005\projects\helloworld\helloworld\main.cpp(8) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [19]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\Pat Eason\My Documents\Visual Studio 2005\Projects\HelloWorld\HelloWorld\Debug\BuildLog.htm"
HelloWorld - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is really confusing since, essentially, this is copied directly from that programming book. The disc that came with it has the correct source code, and that wont even compile. Any help would be greatly appreciated.
 
MessageBoxW
The 'W' on the end stands for Wide. This means somewhere in your project settings you have UNICODE defined.

You can either write all your strings in UNICODE like this:
Code:
MessageBox(NULL, [COLOR=red]L[/color]"Starting off small",
        [COLOR=red]L[/color]"BlackZer0", MB_OK);

or

MessageBox(NULL, [COLOR=red]_T([/color]"Starting off small"[COLOR=red])[/color],
        [COLOR=red]_T([/color]"BlackZer0"[COLOR=red])[/color], MB_OK);
or you can get rid of the UNICODE definition, in which case it would be compiling with MessageBoxA (the 'A' stands for ASCII).
 
Thank you so much. It works perfectly now. I've never messed with programming before, so all the ANSC and UNICODE are still new to me. I'm catching on though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top