Join 132,613 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 950 people online right now. Registration is fast and FREE... Join Now!
I believe (& this is going back a ways) that what I've done in the past to force this to work is create a char array & pass that in the argument, rather than the string/text. I think... it's been a while since I've done Windows coding.
When you simply copy-paste code and execute it in VC++ 6.0 IDE, it creates a default workspace for a console project. Console projects expect a main() function instead of WinMain() and hence it won't compile.
Create a New Project and select the Win32 Application option and then compile the code.
When you simply copy-paste code and execute it in VC++ 6.0 IDE, it creates a default workspace for a console project. Console projects expect a main() function instead of WinMain() and hence it won't compile.
Create a New Project and select the Win32 Application option and then compile the code.
i'm using microsoft visual c++ 2008 express edition and it has a 'win32 project.' is that 'good enough'?
Microsoft has two variations to a lot of their functions, a ASCII and a Unicode version. If you see a function with a "W" at the end of the name (As your error code says), then you are running in Unicode come. If there is a "A" at the end, then it's ASCII.
The L in front of a string tells the compiler to convert the ASCII string to Unicode. This will only work for string literals though.
If you want to use the ASCII versions by default, then make sure that _UNICODE and UNICODE are *NOT* defined. If you're using Visual C++, there should be an option for preprocessor definitions in the compilation options.
The best way to do this IMHO is to write your code so that it can be compiled either way:
cpp
#include <windows.h>
// Note this: #include <tchar.h>
// Note: _tWinMain doesn't work in MinGW. In this case, there is a workaround. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, _T("Hello World"), _T("Hello World"), MB_OK); return 0; }
In this case, _T("string") is expanded to L"string" when the *W functions are to be used, or just "string" when the ASCII version are to be used.
In the API documentation, you will find many references to LPTSTR, LPCTSTR, TCHAR[], etc. For these strings, just use _T(...) around it to have it automatically adapted to the compilation environment.
Don't typecast the strings to LPCWSTR inspite of the compiler asking you to do so. Because by doing so, an ASCII string is considered as Unicode and as a result, the MessageBox displays the text in the Chinese font (because the characters match the unicode string) like this:
Typecasting does not convert ASCII to Unicode, it merely considers an ASCII string as a Unicode string.
If you want to use the ASCII versions by default, then make sure that _UNICODE and UNICODE are *NOT* defined. If you're using Visual C++, there should be an option for preprocessor definitions in the compilation options.
um...where exactly ARE these compilation options? i am very tired and can't find them.