Hi all i want to use GUI wıth the Mıcrosoft vısual C++. I have taken some reference code for Win32 GUI and compiled ıt..but ı was gettıng error to compile this code.

This is the code which ı compiled...

#include <windows.h>

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

İam getting following error..
error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Recommended Answers

All 5 Replies

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

İam getting following error..
error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

There is more then one way to solve this, the easiest is changing the MessageBox line to:

MessageBox(NULL, L"Goodbye, cruel world!", "Note", MB_OK);

The problem is that you compiled your project for 'unicode'. So the other way to solve the problem is going to project->properties->general and change 'unicode' to 'multibyte'

İ have changed my message Box as you have shown..still it shows the following error...


error C2664: 'MessageBoxW' : cannot convert parameter 3 from 'const char [5]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Whoops, my bad, it's kind of early here :)

What I meant was:

MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK);

Sorry about that

Hi thanks for your effort...but still ıam gettıng two errors...

error LNK2019: unresolved external symbol _main referenced in function___tmainCRTStartup

fatal error LNK1120: 1 unresolved externals

The linker is complaining that you don't have a main(), how did you create this project? If I go to new project->win32->win32 project this code compiles fine!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.