Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8258141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:26:12+00:00 2026-06-08T02:26:12+00:00

I am talking about winprog.org’s tutorial on windows GUI because many users on StackO

  • 0

I am talking about winprog.org’s tutorial on windows GUI because many users on StackO recommended it.

I basically tried this example:

#include "stdafx.h"
#include "winapiTest1.h"


int WINAPI _tWinMain(HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPTSTR    lpCmdLine,
        int       nCmdShow)
{
    MessageBox(NULL, (LPCWSTR) "Goodbye, cruel world!", (LPCWSTR) "Note", MB_OK);
    return 0;
}

But when I run it, it shows the message box but every string in it (even the title) is represented in Chinese characters.

What seems to be the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:26:15+00:00Added an answer on June 8, 2026 at 2:26 am

    But when I run it, it shows the message box but every string in it
    (even the title) is represented in Chinese characters.

    The reason why is because the operating system is interpreting your string literals as if they were encoded using UTF-16, even though they’re not.

    Some identifiers like MessageBox() comes in two flavors: a MessageBoxA() function and a MessageBoxW(). MessageBoxA() is the “ANSI” version that accept strings encoded in the current code page, and MessageBoxW() is the “wide” version that accept strings encoded in UTF-16 (i.e. it is “Unicode-aware”). MessageBox() is actually a macro that defines to either one of those depending on whether the UNICODE macro is defined. There is no actual function in the Windows API that is called MessageBox() per se.

    The crux of the problem is here:

    MessageBox(NULL, (LPCWSTR) "Goodbye, cruel world!", (LPCWSTR) "Note", MB_OK); 
    

    Your project probably has a #define UNICODE somewhere, causing the MessageBox() identifier to resolve to MessageBoxW(), which expects a UTF-16 encoded string. Normally, the compiler would have complained to you about it (i.e. compilation error), but the LPCWSTR cast essentially shuts the compiler up and forces it to compile.

    You cannot just throw in a random cast and always expect it to work. Unfortunately lots of Windows API tutorials (and some C++ tutorials in general) abuse casts all over the place when they’re not necessary or even when they’re inappropriate.

    The solution that James propose uses the _T() macros, which help set it so the string literal is properly encoded, without requiring casting. However, a superior solution for new applications is to forget about the ANSI versions of the functions and simply work in Unicode the entire time. The _T() macro is a stopgap for applications transitioning to the Unicode-aware APIs.

    #include "stdafx.h"   // Make sure UNICODE is defined before windows.h       
    #include "winapiTest1.h"          
    
    int WINAPI WinMain(HINSTANCE hInstance,          
            HINSTANCE hPrevInstance,          
            LPCSTR    lpCmdLine,          
            int       nCmdShow)          
    {          
        MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK);          
        return 0;          
    }         
    

    Note that the string literals now have an L prefixed to them. This tells the Visual C++ compiler to interpret the literal as a UTF-16 encoded string (note that it might turn it into a different encoding on other C++ compilers; this applies to Visual C++ only).

    Also note that the above advice applies only when working with only the Windows API. Some frameworks and libraries that wrap the Windows API has their own provisions for handling Unicode strings. Follow those instead, if you are using a framework/library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I heard many people talking about signing exe in windows platforms. I have following
I'am talking about this example of a Scilab<->C wrapper: http://www.scilab.org/doc/intro/node89.html . The strange part
Talking about Hybid Auth , I'm using Facebook to login the users, but I
I am talking about Device resolution not screen size. I saw many previous questions'
I'm not talking about doing anything fancy. I'd just like the standard windows and
I'n talking about the small windows with buttons that come from the bottom when
The websites I am talking about - codecademy.com and tryruby.org . My guess would
I see many people talking about the term SUT, but do not understand why
Talking about javax.crypto.Cipher I was trying to encrypt data using Cipher.getInstance(RSA/None/NoPadding, BC) but I
Talking about SimpleModal the jQuery plugin. Most of the time I think it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.