VS compiler error???

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

VS compiler error???

 
0
  #1
Mar 30th, 2007
I have this code (example)
  1.  
  2. const char g_sz_className[] = "myWindowClass";
  3.  
  4. LRESULT CALLBACK WndProc(HWND hwnd, UNIT msg,WPARAM wParam, LPARAM lPraram)
  5. {
  6. switch(msg)
  7. {
  8. case WM_CLOSE:
  9. DestroyWindow(hwnd);
  10. break;
  11. case WM_DESTROY:
  12. PostQuitMessage;
  13. break;
  14. default:
  15. return DefWindowProc(hwnd, msg, wParam, lParam);
  16. }
  17. return 0;
  18. }
  19.  
  20. int WINAPI WinMain(HISTANCE hIstance, HISTANCE hPrevIstance, LPSTR lpCmdLine, int nShowCmd)
  21. {
  22.  
  23. WNDCLASSEX wc;
  24. HWND hwnd;
  25. MSG Msg;
  26.  
  27. wc.cbSize = sizeof(WNDCLASSEX);
  28. wc.style = 0;
  29. wc.cbClsExtra = 0;
  30. wc.cbWndExtra = 0;
  31. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  32. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  33. wc.hInstance = hIstance;
  34. wc.hbrBackground = (HBRUSH) 13;
  35. wc.lpfnWndProc = WndProc;
  36. wc.lpszClassName = g_sz_className;
  37. wc.lpszMenuName = NULL; //change
  38.  
  39. if(!RegisterClassEx)
  40. {
  41. MessageBox(NULL, "Err", "ERR", MB_OK | MB_EXCLAMATION);
  42. return 0;
  43. }
  44.  
  45. hwnd = CreateWindowEx(
  46. WS_EX_CLIENTEDGE,
  47. g_sz_className,
  48. "My app",
  49. WS_OVERLAPPEDWINDOW,
  50. CW_USERDEFAULT,
  51. CW_USERDEFAULT,
  52. 600,
  53. 650,
  54. NULL,NULL, hIstance, NULL);
  55.  
  56. if(hwnd = NULL)
  57. {
  58. MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONEXCLAMATION);
  59. return 0;
  60. }
  61.  
  62. ShowWindow(hwnd, nCmdShow);
  63. UpdateWindow(hwnd);
  64.  
  65. while(GetMessage(&Msg, NULL, 0, 0) > 0)
  66. {
  67. TranslateMessage(&Msg);
  68. DispatchMessage(&Msg);
  69. }
  70.  
  71. return Msg.wParam;
  72.  
  73.  
  74.  
  75. }

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: VS compiler error???

 
0
  #2
Mar 30th, 2007
Where can I get a good tutorial or book which will teach me Win32 API as Visual Studio wants???
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: VS compiler error???

 
0
  #3
Mar 30th, 2007
>>But it looks like its not portable
Of course not -- its only for MS-Windows

Tutorial here
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: VS compiler error???

 
0
  #4
Mar 30th, 2007
sorry, but I am affraid this damn code is from link you just gave me...

Is there any good book?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: VS compiler error???

 
0
  #5
Mar 30th, 2007
> PostQuitMessage;
Maybe if this were a function call, say
PostQuitMessage(0);

Perhaps posting actual error messages instead of "it doesn't work" would help as well.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: VS compiler error???

 
0
  #6
Mar 30th, 2007
h I am so sorry,

I was in hurry when writing that code and it is full od bugs...

Sorry
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: VS compiler error???

 
0
  #7
Mar 30th, 2007
Originally Posted by jan1024188 View Post
sorry, but I am affraid this damn code is from link you just gave me...

Is there any good book?
The code in that link is perfect -- billions of people (:eek: ) have used it.
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: VS compiler error???

 
0
  #8
Mar 31st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: VS compiler error???

 
0
  #9
Mar 31st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: VS compiler error???

 
0
  #10
Mar 31st, 2007
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
Last edited by jan1024188; Mar 31st, 2007 at 6:09 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC