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

  • SEARCH
  • Home
  • 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 3854628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:39:07+00:00 2026-05-19T17:39:07+00:00

I’ve found that NetUserChangePassword(0, 0, Lab, Lcd); changes the user password from ab to

  • 0

I’ve found that

NetUserChangePassword(0, 0, L"ab", L"cd");

changes the user password from ab to cd. However,

NetUserChangePassword(0, 0, (LPCWSTR) "ab", (LPCWSTR) "cd");

doesn’t work. The returned value indicates invalid password.

I need to pass const char* as last two parameters for this function call. How can I do that? For example,

NetUserChangePassword(0, 0, (LPCWSTR) vs[0].c_str(), (LPCWSTR) vs[1].c_str());

Where vs is std::vector<std::string>.

  • 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-05-19T17:39:08+00:00Added an answer on May 19, 2026 at 5:39 pm

    Those are two totally different L‘s. The first is a part of the C++ language syntax. Prefix a string literal with L and it becomes a wide string literal; instead of an array of char, you get an array of wchar_t.

    The L in LPCWSTR doesn’t describe the width of the characters, though. Instead, it describes the size of the pointer. Or, at least, it used to. The L abbreviation on type names is a relic of 16-bit Windows, when there were two kinds of pointers. There were near pointers, where the address was somewhere within the current 64 KB segment, and there were far, or long pointers, which could point beyond the current segment. The OS required callers to provide the latter to its APIs, so all the pointer-type names use LP. Nowadays, there’s only one type of pointer; Microsoft keeps the same type names so that old code continues to compile.

    The part of LPCWSTR that specifies wide characters is the W. But merely type-casting a char string literal to LPCWSTR is not sufficient to transform those characters into wide characters. Instead, what happens is the type-cast tells the compiler that what you wrote really is a pointer to a wide string, even though it really isn’t. The compiler trusts you. Don’t type-cast unless you really know better than the compiler what the real types are.

    If you really need to pass a const char*, then you don’t need to type-cast anything, and you don’t need any L prefix. A plain old string literal is sufficient. (If you really want to cast to a Windows type, use LPCSTR — no W.) But it looks like what you really need to pass in is a const wchar_t*. As we learned above, you can get that with the L prefix on the string literal.

    In a real program, you probably don’t have a string literal. The user will provide a password, or you’ll read a password from some other external source. Ideally, you would store that password in a std::wstring, which is like std::string but for wchar_t instead of char. The c_str() method of that type returns a const wchar_t*. If you don’t have a wstring, a plain array of wchar_t might be sufficient.

    But if you’re storing the password in a std::string, then you’ll need to convert it into wide characters some other way. To do a conversion, you need to know what code page the std::string characters use. The “current ANSI code page” is usually a safe bet; it’s represented by the constant CP_ACP. You’ll use that when calling MultiByteToWideString to have the OS convert from the password’s code page into Unicode.

    int required_size = MultiByteToWideChar(CP_ACP, 0, vs[0].c_str(), vs[0].size(), NULL, 0);
    if (required_size == 0)
      ERROR;
    // We'll be storing the Unicode password in this vector. Reserve at
    // least enough space for all the characters plus a null character
    // at the end.
    std::vector<wchar_t> wv(required_size);
    int result = MultiByteToWideChar(CP_ACP, 0, vs[0].c_str(), vs[0].size(), &wv[0], required_size);
    if (result != required_size - 1)
      ERROR;
    

    Now, when you need a wchar_t*, just use a pointer to the first element of that vector: &wv[0]. If you need it in a wstring, you can construct it from the vector in a few ways:

    // The vector is null-terminated, so use "const wchar_t*" constructor
    std::wstring ws1 = &wv[0];
    // Use iterator constructor. The vector is null-terminated, so omit
    // the final character from the iterator range.
    std::wstring ws2(wv.begin(), wv.end() - 1);
    // Use pointer/length constructor.
    std::wstring ws3(&wv[0], wv.size() - 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.