Jump to content
  • Advertisement
Sign in to follow this  

I Have a Problem in "char *" & "LPCWSTR"

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm studying OpenGL Programming in http://nehe.gamedev.net/

I'm in Tutorial #0 right now. (http://nehe.gamedev.net/tutorial/creating_an_opengl_window_(win32)/13001/)

I read the whole page, and coded all source code in my Visual Studio 2015.

I have a problem in all strings.

For example, 




there I have 2 errors in between \" respectively.


I found the solution that include tchar.h header file and modify the code like :

MessageBox(NULL, _T("Release Of DC And RC Failed"), _T("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION);


then, there are no red underline now, but I still have a trouble.


in the code:


if (!(hWnd = CreateWindowEx(dwExStyle,                                    // Extended Style For The Window
"OpenGL",                                                                                    // Class Name
title,                                                                                              // Window Title
WS_CLIPSIBLINGS |                                                                   // Required Window Style
WS_CLIPCHILDREN |                                                                 // Required Window Style
dwStyle,                                                                                      // Selected Window Style
0, 0,                                                                                             // Window Position
WindowRect.right - WindowRect.left,                                          // Calculate Adjusted Window Width
WindowRect.bottom - WindowRect.top,                                      // Calculate Adjusted Window Height
NULL,                                                                                          // No Parent Window
NULL,                                                                                          // No Menu
hInstance,                                                                                   // Instance
NULL)))                                                                                       // Don't Pass Anything To WM_CREATE
here the title is the string variable.
I changed it to :
but as you think, it was not the solution.
how can I get through this problem? Please HELP me.

Share this post

Link to post
Share on other sites
The W in LPCWSTR stands for "Wide" and usually if you see errors about that it means you're mixing Unicode and Multibyte strings in your program due to incorrect settings or incorrect string literals.

You can either try making everything consistently Unicode (put L prefixes on all of your string literals or the _T macro like you've already tried) or consistently Multibyte (open your project properties and change "Character Set" to "Use Multibyte Character Set".

If that doesn't help then the problem is much deeper and you might need to post more code.

New VS2015 C++ windows projects default to Unicode, I believe. Older tutorials like NeHe probably assume the older multibyte default. Edited by Nypyren

Share this post

Link to post
Share on other sites

I have to really, really recommend you learn modern OpenGL.  NeHe is very out of date with anything modern and little of it will translate over.  Look for OpenGL 3 or 4 tutorials, there are plenty online.


As Mike said, you'd better learn modern OpenGL instead of the old fixed pipeline like on NeHe.

Have a look at  http://www.learnopengl.com/.



Using WinAPI directly is also not the nicest way to do it, since its platform specific. I'd suggest to use something like GLFW (or SDL/Allegro/SFML but they are higher level), but its your choice.



Can I ask why downvote? Maybe its not what the OP asked but its important for him to know.

Edited by Matth

Share this post

Link to post
Share on other sites

Thanks to Everybody! As you guys suggested, I should learn modern OpenGL haha.


Anyway, I solved my problem not modifying the codes, I changed my project property so not using character set in Unicode, but Multibyte. Who must study old OpenGL in some reasons, this would help you guys~

Share this post

Link to post
Share on other sites

Incidentally, if you want to represent either LPSTR and LPWSTR depending on compiler settings you can use LPTSTR.

Share this post

Link to post
Share on other sites

Most Win32 functions that take a string argument actually have two different versions for two different string types - ANSI strings and WIDE strings.

ANSI strings use some sort of multi-byte encoding (or just plain old ASCII) and resolve to char*. WIDE strings use UTF-16 encoding and resolve to wchar_t *.

For example, there is no actual MessageBox function. It's actually a trick that the Windows headers play - when there are ANSI and WIDE versions of a function, the windows headers automatically choose the right function for MessageBox to resolve to, based on your project settings. It looks something like this:

#ifdef _UNICODE

#define MessageBox MessageBoxW


#define MessageBox MessageBoxA


Usually I just use the ANSI version, unless I have reason to believe I'll translate my project into a language other than English. Working with WIDE strings is more work. :)


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!