Public Group

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

This topic is 4426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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
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 on other sites
Go to your project properties, under general, change the Character Set setting to "Use Multi-Byte Character Set"

##### 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 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 on other sites
thanx for that, that was very helpful. very informative.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631786
• Total Posts
3002350
×