| | |
Why program works in Dev-C++ and not in VC++ 2005?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hello ladies and gents,
I just wanted to see what this small programs does so I tried it in Dev-C++ and in VC++ 2005, thing was, it worked in Dev-C++ but not in VC++ 2005 in which I got an error stating the following:
The program I tried was one which Ancient Dragon gave a link to in another thread:
Could anyone tell me why it works in the one, but not in the other
Thanks.
I just wanted to see what this small programs does so I tried it in Dev-C++ and in VC++ 2005, thing was, it worked in Dev-C++ but not in VC++ 2005 in which I got an error stating the following:
•
•
•
•
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
C++ Syntax (Toggle Plain Text)
// WinApi.cpp : Defines the entry point for the console application. #include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK); return 0; }
Could anyone tell me why it works in the one, but not in the other
Thanks.
LPCWSTR is a wide string type and a string literal is a narrow string type. The two aren't compatible. You can fix it in a number of ways. First, you can make the string wide by prefixing it with L, or you can use the _TEXT macro provided by the Win32 API for selecting the right string width to match your settings. Or you can use MessageBoxA directly instead of using MessageBox as a "smart" entry point.
>Could anyone tell me why it works in the one, but not in the other
MessageBox calls either MessageBoxA or MessageBoxW depending on the need to use 1 or 2 byte character sizes. I'm inclined to think that your Visual Studio setup is conflicting with your needs somewhere while Dev-C++'s setup isn't.
>Could anyone tell me why it works in the one, but not in the other
MessageBox calls either MessageBoxA or MessageBoxW depending on the need to use 1 or 2 byte character sizes. I'm inclined to think that your Visual Studio setup is conflicting with your needs somewhere while Dev-C++'s setup isn't.
I'm here to prove you wrong.
•
•
•
•
Originally Posted by Narue
I'm inclined to think that your Visual Studio setup is conflicting with your needs somewhere...
$(ProgramFiles)\Microsoft Platform SDK\lib
$(ProgramFiles)\Microsoft Platform SDK\bin
$(ProgramFiles)\Microsoft Platform SDK\include
The way it was showed on the video, it seemed that these three had to be added to the executable files, but, when I did that, I got an error message saying that <windows.h> could not be found.
When I added the "$(ProgramFiles)\Microsoft Platform SDK\include" directory to the include files, that problem was gone, however, I'm now getting the mentioned error.
Do I have to include all three directories to the executable-include- and library files?
It was showed that I had to add them by pressing tools->options->Projects and Solutions->VC++Directories->there I found the several files, but as said, it seemed as if I had to add the three directories only into the executable file, but this gave me the error that <window.h> couldn't be found???
Visual Studio has enabled Unicode support by default. So even though you have written MessageBox, as Narue said, it calls MessageBoxW because of this setting.
Try setting to "Use Multi-Byte Character Set" or "Not Set", and compile. It should work.
The usual way programmers tell the compiler to use the Wide String format or not is by setting the #define UNICODE preprocessor switch.
Try setting
C++ Syntax (Toggle Plain Text)
Project--->Propoerties-->Configuration Properties-->General-->Character Set
The usual way programmers tell the compiler to use the Wide String format or not is by setting the #define UNICODE preprocessor switch.
As for the second problem, there is a drop down box to select the type you are adding the directory. See the attached bitmap.
$(ProgramFiles)\Microsoft Platform SDK\lib ---- To Library Files
$(ProgramFiles)\Microsoft Platform SDK\bin ---- To executable Files
$(ProgramFiles)\Microsoft Platform SDK\include ----- To Include Files
$(ProgramFiles)\Microsoft Platform SDK\lib ---- To Library Files
$(ProgramFiles)\Microsoft Platform SDK\bin ---- To executable Files
$(ProgramFiles)\Microsoft Platform SDK\include ----- To Include Files
•
•
•
•
Originally Posted by WolfPack
Byte Character Set" or "Not Set", and compile. It should work.
•
•
•
•
WinApi.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\Visual Studio 2005\Projects\WinApi\Debug\WinApi.exe : fatal error LNK1120: 2 unresolved externals
Beats me, it ought to work. Anyway change the Character set to what it was ( Unicode ) and run this code and tell me what happens.
C++ Syntax (Toggle Plain Text)
// WinApi.cpp : Defines the entry point for the console application. #include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK); return 0; }
•
•
•
•
Originally Posted by WolfPack
... and run this code and tell me what happens.
•
•
•
•
WinApi.obj : error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _WinMain@16
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\Visual Studio 2005\Projects\WinApi\Debug\WinApi.exe : fatal error LNK1120: 2 unresolved externals
•
•
•
•
Originally Posted by Narue
>error LNK2019: unresolved external symbol _main referenced in function
You're using a console application?
[Edit]
Okay I think I know what your problem is. Building Win32 Applications is disabled in the Visual Studio 2005 by default. You can build only Console Programs as it is. To create Win32 Applications look at this article by Brian Johnson.
![]() |
Other Threads in the C++ Forum
- Previous Thread: (Noob) need some help w/ Prime Numbers
- Next Thread: Avoid PROGRAM CRASH
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






