Wow i am suprised i cant find this....  
Author Message
Tiberius147





PostPosted: Visual C++ General, Wow i am suprised i cant find this.... Top

I searched google i searched here and i searched mIrc and no one seems to know how to do this, they tell me to use a difrent compiler but i love microsoft and could not do that. I am sure you guys probably covered it some where but i can't find it so here goes. I use visual studio 2005 standard edition. I recently finished learning the core language of c++ and am moving on to implement that knowledge with win api in which i am trying to learn now. I am using this tutorial to learn win api http://www.hide-link.com/
Obviously i cant use the old new >> console application >> empty project
because it doesn't work, i tryed new >> win 32 project >> pre-compiled header and empty project but none work.

This is the source I am trying to compile :

#include <windows.h>

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

and usually i have to add "stdafx.h"
but i always get the error error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'

please help me i am so frustrated and just want to get making games again.



Visual C++11  
 
 
Bite Qiu - MSFT





PostPosted: Visual C++ General, Wow i am suprised i cant find this.... Top

hello

The "W" in MessageBoxW" function means _Unicode has been defined somewhere in your project, so you should use _T macro to tag your string literal, try to modify it as following:

MessageBox(NULL, _T("Goodbye, cruel world!"), _T("Note"), MB_OK | MB_SYSTEMMODAL);

hope this helps you

Bite



 
 
Simple Samples





PostPosted: Visual C++ General, Wow i am suprised i cant find this.... Top

You should send a message to the author, because eventhough the author says that you should figure out those things yourself, the problem you encountered will be common and people should not be required to get help in this and other forums. Or something like that.

 
 
einaros





PostPosted: Visual C++ General, Wow i am suprised i cant find this.... Top

i always get the error error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'

See http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=849851&SiteID=1.



 
 
Tiberius147





PostPosted: Visual C++ General, Wow i am suprised i cant find this.... Top

thats kind of a pain in the butt, just because i use vs means i should have to add _T before everything well even if i were to do that for everything i cant possibly convert this :
#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
i don't care what i have to do i just want to be able to paste this code in and compile, because other wise learning win api using http://www.winprog.org/tutorial/ will be impossible.

 
 
Simple Samples





PostPosted: Visual C++ General, Wow i am suprised i cant find this.... Top

i don't care what i have to do i just want to be able to paste this code in and compile, because other wise learning win api using http://www.winprog.org/tutorial/ will be impossible.
An important part of programming is reading. Read again what Bite Qiu said; especially the part about "_Unicode has been defined". That does not provide a solution directly, but it is a clue. Also see Einar's (einaros's) reply.

The reason that you are having problems is that when that sample code was written, Unicode was not the default. For VS 2005, Unicode is the default. So you simply need to change your project settings to not use Unicode by default.

You should explore the many project settings. You are not likely to understand all of them, but you can probably find the setting to specify whether to use Unicode by default. One thing to look for is the list box that is used to specify what configurations that the setting applies to. It is always set to the current configuratrion, such as Debug, but you usually want to change that to All Configurations so that the setting applies to both Debug and Release. If you don't, then when you do a Release build, you will again get errors due to Unicode being the default.