Sign in to follow this  
Damnation

[C++] Problem compiling book example win32/gdi

Recommended Posts

i did a quick search, and resulted in finding nothing, so sorry if this is a repost. basically i am going through "Tricks of the windows game programming gurus second ed" and i though i'd compile some of the source, and make sure my IDE is setup and able too. so i loaded up Demo 4_1 ran the compiler and go these errors
[source=cpp]
main.cpp(41) : warning C4101: 'buffer' : unreferenced local variable
main.cpp(108) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(129) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(182) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data


[source=cpp]
Line 16  :  #define WINDOW_CLASS_NAME "WINCLASS1"
Line 108 :  winclass.lpszClassName  = WINDOW_CLASS_NAME;
Line 129 : if (!(hwnd = CreateWindowEx(NULL,                // extended style
                            WINDOW_CLASS_NAME,   // class
						    "Pixel Plotting Demo", // title
						    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    WINDOW_WIDTH, // initial width
                            WINDOW_HEIGHT,// initial height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms


i use visual studio 2005 pro, as my ide, i have the platform sdk + directx sdk installed, and afaik correctly added to the IDE. i have winmm.lib, added to the linker as well. i don't understand why its upset. the line xxx : i added here to help, that is not in the source. other than the Ide's built in line numbers. thank you for any response, as to what the problem is. or even better how to sort it

Share this post


Link to post
Share on other sites
Go to your project properties, under general, change the Character Set setting to "Use Multi-Byte Character Set"

Share this post


Link to post
Share on other sites
thanx that sorted it, but why was i getting that error, i mean whats the difference between the two settings?


(unicode / multibyte)


Thanx for any response

Share this post


Link to post
Share on other sites
Most Windows API functions and structures come in two versions: a narrow character version and a wide character version. These are also known as ANSI and Unicode versions. For example, CreateWindow() is actually two functions: CreateWindowA() and CreateWindowW(). A macro transformation maps CreateWindow() calls to one of these two functions depending on what preprocessor definitions are in effect. If UNICODE is defined, CreateWindow() is actually CreateWindowW(). If it isn't defined CreateWindow() is actually CreateWindowA(). In MSVC, the Character Set project property controls whether or not UNICODE is defined.

The difference between the two versions is that the ANSI versions use CHARs for their character type in strings. The wide character versions use WCHARs for their character types. Normal string literals in C++ are narrow characters, which is what the CHAR type works out to. However, WCHAR eventually turns into wchar_t, not char, and pointers to normal char strings are not compatible with pointers to wchar_ts. In order to create a wchar_t string literal you would prefix the string with L. For example "this is a narrow character string" vs. L"this is a wide character string".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this