So, I've bought two books, one on DirectX 10 and one on OpenGL. The first one i bought was the directX 10 book, and NONE of the code compiled because of some LPCSTR error. So stupid me thinking it was another thing that microsoft goofed on i bought a book that teaches OpenGL. THE SAME THING HAPPENED!!! I have no clue how to fix it and i'm about done with 3D API's. What can i do? I've included all the right files and everything, I'm not sure what to do. I know it has something to do with the win32 window because i've done almost all of the video tutorials with source code on http://videotutorialsrock.com and all of it compiled beautifully. Do you know of any videos that would help me understand OpenGl in concurrency with windows? Right now i'm mainly focussed on OpenGl because i've sunk ALOT of money into it, but i would still welcome any DirectX suggestions. Thanks alot guys I really appreciate all the help you've given me.

Dani AI

Generated

As and already hinted, this is not an OpenGL/DirectX bug but a Windows string/encoding mismatch: older samples often use the single-byte (ANSI/MBCS) APIs while modern Visual Studio projects default to Unicode. The Windows headers expose both narrow and wide string typedefs and provide generic mappings so the same API name can resolve to either variant depending on your project character set. Windows Data TypesUsing Generic Data Types. (learn.microsoft.com)

Practical fixes (pick one that fits your situation):

  • Change the project Character Set to match the sample code (Project → Properties → Configuration Properties → General → Character Set). Old samples typically expect the multi-byte setting; modern apps should prefer Unicode. [Visual Studio guidance on character set]. (learn.microsoft.com)
  • Make the code encoding-safe: use the generic macros/types or explicit wide/narrow literals and the A/W function variants consistently. The TEXT/_T macros and TCHAR-based patterns let the same source compile in either mode. (learn.microsoft.com)
  • For third-party or library boundaries, convert strings explicitly (do not cast away constness). Use the Win32 conversion APIs when crossing between UTF-8/ANSI and UTF-16.

A minimal practical example: convert a UTF-8 std::string to a UTF-16 std::wstring using the Win32 API before calling Unicode-only functions.

std::wstring to_wstring_utf8(const std::string& s) {
    if (s.empty()) return {};
    int n = MultiByteToWideChar(CP_UTF8, 0, s.data(), (int)s.size(), nullptr, 0);
    std::wstring w;
    if (n > 0) {
        w.resize(n);
        MultiByteToWideChar(CP_UTF8, 0, s.data(), (int)s.size(), &w[0], n);
    }
    return w;
}

See the MultiByteToWideChar documentation for buffer-size and security notes. (learn.microsoft.com)

If handling Win32 window creation is getting in the way of learning OpenGL, consider using a small cross-platform helper (GLFW or SDL) so tutorials focus on GL rather than Win32 string/encoding details. Both provide simple window/context setup that avoids the LP*/TCHAR boilerplate. GLFWSDL. (glfw.org)

Checklist: ensure the project Character Set, any library build settings, and the literal types in source (narrow vs wide) are all consistent; avoid const-correctness violations; prefer explicit conversion functions rather than casts.

Recommended Answers

All 3 Replies

Try changing your project options to not use unicode.

LPCSTR = Long Pointer to a C-style STRing
C = char *

Microsoft typedefs their actual types, and if your project options are set to use unicode a different typedef is used for supporting unicode.

(it may be LPCWSTR)

You can read the first few pages of a book on Windows programming and it will probably tell you all about their naming system.

The "Long Pointer" part is outdated, pointers long ago were different.

Actually, to correct pseudorandom21: LPCSTR stands for Long Pointer to a Constant STRing.
So LPCSTR indicates that the pointer is a const char* NOT a char* Incidentally, using the Microsoft naming conventions a char * pointer would be LPSTR !

As pseudorandom21 has correctly pointed out, you may need to use LPCWSTR if you're using unicode in your project.

Another thing to bear in mind is that the C in LPCSTR and LPCWSTR stands for constant. i.e. These are pointers to constant strings. So if you're getting error messages saying things like 'cannot convert const char* to char*' or 'cannot convert char* to const char*' then you may need to take a look at how you're using and/or storing the strings in question!

However as you haven't posted the exact errors you're getting regarding the LPCSTR's this is all conjecture! If you'd post some snippets of relevant code and some of the errors you're getting, somebody may be able to offer further help on this!

Thanks, didn't know that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.