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

Posted on 2008-11-20
Medium Priority
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

Assisted Solution

ChristianWimmer earned 400 total points
ID: 23003467
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 40

Accepted Solution

evilrix earned 1600 total points
ID: 23006585
>> : 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)

Author Closing Comment

ID: 31518668

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

840 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