Very Simple Win32 API Code! Weird Compiler Error Need to Be Fixed! Help

Posted on 2008-11-20
Last Modified: 2013-11-25
I have been trying to start learning Win32 API on GUI's. Eventhough my code is right, i keep getting compiler errors!

This my main code as you see it below.

When i compile it, i get this nonsense ***error:

c:\users\user\desktop\win32\mysource\ttt\ttt\ttt.cpp(5) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [4]' to 'LPCWSTR'
 Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 1>Build log was saved at "file://c:\Users\user\Desktop\Win32\mySource\ttt\ttt\Debug\BuildLog.htm"
 ttt - 1 error(s), 0 warning(s)

However, i fixed it, i had to do something with Unicode in the config. box

I compile the program again, i get ***error that says my code does not include #include"stdafx.h", or something similar.

I added #include "stdafx.h" at the top. I recompiled, i get this ***error:

c:\users\user\desktop\win32\mysource\ttt\ttt\ttt.cpp(2) : fatal error C1083: Cannot open precompiled header file: 'Debug\ttt.pch': No such file or directory
. Build log was saved at "file://c:\Users\user\Desktop\Win32\mySource\ttt\ttt\Debug\BuildLog.htm"

NOTE: my vista got too many problems, many lost system files. Every time, i open VC++ Express
i get this error below:

The Visual Studio Debugger ({C9DD4A57-47FB-11D2-83E7-00C04F9902C1}) did not load because of previous errors. For assistance, contact the package vendor. To attempt to load this package again, type 'VCExpress /resetskippkgs' at the command prompt

Anyhow, i think this one of the reasons why my code does not compile, but i found many people face same 3 errors i mentioned above.

Can you help please?

Extra question: Does VC++ Express (Free version) support Win32 API & MFC fully?


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR IpCmdLine, int nCmdShow)


	MessageBox(NULL, "Hey", "NOTE", MB_OK);

	return 0;


Open in new window

Question by:F-J-K
    LVL 6

    Assisted Solution

    1. Unicode :
    use _T("mytext") instead of "mytext" everywhere you want to use static text.

    2. PreCompiled Header
    You can remove precompiled headers for a cpp files separately. Right click on you cpp file and choose Properties. Go to C/C++-> Precompiled Headers in the thread and deactivate it.
    As far as I know, a new project should be built at least once without moditication. If this problem persist maybe files could not be written to disk?

    3. Package Error. I don't have Express version. But imo you should de- and reinstall the product. If you seriously damaged your Windows you also should consider to reinstall it. You properly will get more errors in different applications.

    4. MFC/API is supported fully imo.
    LVL 39

    Accepted Solution

    >> : cannot convert parameter 2 from 'const char [4]' to 'LPCWSTR'
    Microsoft insist on using a compile time macro to switch their API between narrow and wide support (for some reason they also insist on referring to wide as Unicode, when it is not. Unicode is a character encoding and has nothing to do with wide or narrow, you can represent Unicode in either 8, 16 or 32 bit data types so why they insist on confusing everyone is beyond me). As CW (above) has pointed out, literal strings should be wrapped withe the _T() macro so they are correctly represented as narrow or wide according to the compile time setting. Also, rather than using char or wchar_t if you stick with TCHAR this'll be either a narrow or wide type according, also, to the compile time setting.

    >> error that says my code does not include #include"stdafx.h", or something similar.
    If you are building with precompile headers enabled you need to ensure you include stdafx.h in all your .c/.cpp files. Alternatively, and what I normally do, just turn of precompiled headers in the project settings. They really don't provide much in the way of benefit unless (a) you are building lots of code and (b) you have structured your code to make good use of them.

    >> my vista got too many problems, many lost system files. Every time, i open VC++ Express
    A standard install of VC++ Express is not compatible with Vista. There is a Vista specific service pack you need to apply.

    >> Does VC++ Express (Free version) support Win32 API & MFC fully?
    Win32 API: of course ---> what do you think MessageBox() is? :)
    MFC : No and for that we are truly grateful! Try looking at the superior (???) Windows Forms (look in the new projects menu)
    LVL 1

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now