   WinAPI error (C++)
  Hello there,A couple of days ago I decided to learn some API programming and I bought a book. Everything is explained clearly and all worked fairly well until I tried to register a windows class; MVSC++ threw up three errors and I haven't got a clue on how to solve them :(. I followed the instructions exact and still...Does anyone know how to solve the errors?Here's the code:-----#include <cstdio>#include <cstdlib>#include <iostream>#include <windows.h>using namespace std;// instead of the normal main, we have WinMainint WINAPI WinMain(   HINSTANCE hInstance, // instance handle of the application   HINSTANCE hPrevInstance, // unused   LPSTR lpCmdLine, // command line options (if any)   int nCmdShow) // show window flag (mini-/maximized){// registering a windows classWNDCLASSEX wcex = {sizeof(WNDCLASSEX), // size of this structureCS_CLASSDC,// style of the windowWindowProc,// Window message procedure0L,// 00L,// 0hInstance,// instance handle from windmainNULL,// handle to application iconNULL,// handle to application cursorNULL,// handle to application brushNULL,// handle to application menu"GameClass",// this class' nameNULL// handle to small application icon};// register the just made class and exit on errorif (!RegisterClassEx(&wcex)) // parameter is the WNDCLASSEX class just created{return FALSE;};// unregister classUnregisterClass("GameClass", hInstance); // parameter 1: class name, parameter 2: instance handle// the normal return 0, to check if the program has executed correctlyreturn 0;}-----Errors:Error1error C2065: 'WindowProc' : undeclared identifier18Error2error C2440: 'initializing' : cannot convert from 'const char [10]' to 'LPCWSTR'26Error3error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char [10]' to 'LPCWSTR'37-----Does anyone know how to solve them?Please help,~ Stenny[Edited by - stenny on June 22, 2006 1:52:09 PM]
  Error 1 is saying that because you dont have a WindowProc function. This function handles the WIN32 messages passed to your window from the OS. You have set a function pointer to it in the WNDCLASSEX.The function should look something like this://-----------------------------------------------------------------------------// Name: WindowProc()// Desc: The window's message handler//-----------------------------------------------------------------------------LRESULT WINAPI WindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){    switch( msg )    {   case WM_DESTROY:  Cleanup();  PostQuitMessage( 0 );  return 0;    }    return DefWindowProc( hWnd, msg, wParam, lParam );}Error 2 & 3 are to do with you converting the string to unicode. Try making the cast to LPCWSTR.Hope that helps,Dave   ;  Im not a c++ guru but,you havent defined your WindowProc variable. I think its an unsigned int. But cant remember.and the const char error. Try this _T("GameClass"). This should convert it correct using the unicode macro "_T".I haven't programmed MFC in a long while. But if memory serves that should answer it.I would suggest an MFC book by jeff prosise or fischer. They have very good ones.Somone else could have a better answer tho.Nick   ;  Error 1: Declare a function prototype of the WindowProc before your WinMain function.Error 2,3: Unicode related problem. Just surround your strings with TEXT () for example the  UnregisterClass("GameClass", hInstance) should be like this  UnregisterClass(TEXT ("GameClass"), hInstance);   ;Quote:Original post by DaveTry making the cast to LPCWSTR.Use the _T or TEXT macro.   ;Quote:Original post by Anonymous PosterQuote:Original post by DaveTry making the cast to LPCWSTR.Use the _T or TEXT macro.Yes, i wasnt entirely sure on this. Thanks.Dave   ;  ---Error 1 is saying that because you dont have a WindowProc function. This function handles the WIN32 messages passed to your window from the OS. You have set a function pointer to it in the WNDCLASSEX.---Isn't it somewhere in the windows header of SDK or I don't know what? Anyway, thank you for helping out and I will search further on my own on that code (maybe it's covered later on).---Use the _T or TEXT macro.---Strange :S. Is it necessary to add those things, because the book I got it from doesn't mention it...You mean all you guys place a _T before it or place it between TEXT()?And if I'm to input the class' name, do I need to put the _T before it too?~ StennyEDIT:I'm fairly new to this forums, but how did you get that code snippet window there dave? I already tried  but that didn't work.   ;  It depends on how the project is set up. You VS project (if that is what you are using) might well be set up as Unicode, which i believe is default. But you could be linking against non-unicode libraries.I could be wrong because i havn't twiddled (what a word!!) with unicode in a while. THE WEB DESIGN HAS TAKEN OVER!Hope that helps,DaveEDIT: Use [/so urce] (without the space after the s), <br><br>BTW you can click edit &#111;n any post to view the syntax, but you won't be able to change anything. Oh, welcome to GD mate.   ;  @DaveThanks man, I checked it and about 10 pages later the Windows Proc will be covered.and indeed , webdesign is cool!@EveryoneDoes anyone know is Dave is right about the Unicode thing, where I could change it and if that would be dangerous?EDIT:Might be handy to tell I use MVSC++.   ;  It wouldn't be dangerous, it's just a case of deciding whether to use unicode or not. These days Unicode is becoming more standardised because of its multilanguage support.Choose one and stick to it :)Dave   