| | |
VS compiler error???
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
I have this code (example)
But it looks like its not portable.
Now in Visual Studio I cannot compile that. There is a bit more complicated file with stdfax.cpp, stdfax.h, resouurce.h files. What should I do?
Where can I get a good tutorial which will teach me Win32 API as Visual Studio wants???
Thanks in advance,
Jan
C++ Syntax (Toggle Plain Text)
const char g_sz_className[] = "myWindowClass"; LRESULT CALLBACK WndProc(HWND hwnd, UNIT msg,WPARAM wParam, LPARAM lPraram) { switch(msg) { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage; break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HISTANCE hIstance, HISTANCE hPrevIstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX wc; HWND hwnd; MSG Msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hIstance; wc.hbrBackground = (HBRUSH) 13; wc.lpfnWndProc = WndProc; wc.lpszClassName = g_sz_className; wc.lpszMenuName = NULL; //change if(!RegisterClassEx) { MessageBox(NULL, "Err", "ERR", MB_OK | MB_EXCLAMATION); return 0; } hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_sz_className, "My app", WS_OVERLAPPEDWINDOW, CW_USERDEFAULT, CW_USERDEFAULT, 600, 650, NULL,NULL, hIstance, NULL); if(hwnd = NULL) { MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONEXCLAMATION); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }
But it looks like its not portable.
Now in Visual Studio I cannot compile that. There is a bit more complicated file with stdfax.cpp, stdfax.h, resouurce.h files. What should I do?
Where can I get a good tutorial which will teach me Win32 API as Visual Studio wants???
Thanks in advance,
Jan
Last edited by Ancient Dragon; Mar 30th, 2007 at 4:18 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Yes I copyed the code from tutorial, and VS compiler gives me this errors.
•
•
•
•
------ Build started: Project: MyFirtsFile, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(40) : error C2440: '=' : cannot convert from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(46) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(57) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(62) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\jan\documents\visual studio 2005\projects\myfirtsfile\myfirtsfile\main.cpp(75) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
Build log was saved at "file://c:\Users\jan\Documents\Visual Studio 2005\Projects\MyFirtsFile\MyFirtsFile\Debug\BuildLog.htm"
MyFirtsFile - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited by jan1024188; Mar 31st, 2007 at 5:24 am.
Finally, actual error messages.
What you have there is a UNICODE problem. VS2003 onwards defaults to using UNICODE for all strings, not ASCII.
Anytime you see functions ending in 'W' or references to 'WSTR', it's a good bet it's something to do with migrating from ASCII to UNICODE.
The fix is pretty easy.
In the project settings, there is a section for the "Preprocessor"
Part of that will be a list of defines which are constant through the whole project (say WIN32). One of those should be "UNICODE", which you should remove.
After you've done that, rebuild it and see what happens.
What you have there is a UNICODE problem. VS2003 onwards defaults to using UNICODE for all strings, not ASCII.
Anytime you see functions ending in 'W' or references to 'WSTR', it's a good bet it's something to do with migrating from ASCII to UNICODE.
The fix is pretty easy.
In the project settings, there is a section for the "Preprocessor"
Part of that will be a list of defines which are constant through the whole project (say WIN32). One of those should be "UNICODE", which you should remove.
After you've done that, rebuild it and see what happens.
Um...I have a problem
Under preprocessor->definitions there is no UNICODE
Its WIN32;_DEBUG;_WINDOWS only
But under list of options I have
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt
I cannot edit that, because text browser is grayed
Under preprocessor->definitions there is no UNICODE
Its WIN32;_DEBUG;_WINDOWS only
But under list of options I have
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt
I cannot edit that, because text browser is grayed
Last edited by jan1024188; Mar 31st, 2007 at 6:09 am.
![]() |
Similar Threads
- Borland compiler error (C++)
- weird compiler error (C)
- internal compiler error (C++)
- Linker error in borland turboc3 compiler.need help in desperation (C++)
- HELP- internal compiler error? (C++)
- Compiler error (C++)
Other Threads in the C++ Forum
- Previous Thread: Help with this program
- Next Thread: misplaced else and removing space characters
| 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







