944,057 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3894
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 30th, 2007
0

VS compiler error???

Expand Post »
I have this code (example)
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Mar 30th, 2007
0

Re: VS compiler error???

Where can I get a good tutorial or book which will teach me Win32 API as Visual Studio wants???
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Mar 30th, 2007
0

Re: VS compiler error???

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Mar 30th, 2007
0

Re: VS compiler error???

sorry, but I am affraid this damn code is from link you just gave me...

Is there any good book?
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Mar 30th, 2007
0

Re: VS compiler error???

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Mar 30th, 2007
0

Re: VS compiler error???

h I am so sorry,

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

Sorry
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Mar 30th, 2007
0

Re: VS compiler error???

Click to Expand / Collapse  Quote originally posted by jan1024188 ...
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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Mar 31st, 2007
0

Re: VS compiler error???

Yes I copyed the code from tutorial, and VS compiler gives me this errors.
Quote ...
------ 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.
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Mar 31st, 2007
0

Re: VS compiler error???

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Mar 31st, 2007
0

Re: VS compiler error???

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.
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help with this program
Next Thread in C++ Forum Timeline: misplaced else and removing space characters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC