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 7631669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:24:49+00:00 2026-05-31T06:24:49+00:00

My function GetErrorString() is passed an error code which is either the result of

  • 0

My function GetErrorString() is passed an error code which is either the result of WSAGetLastError(), or one of the error codes defined in my DLL, which are returned when calls to my DLL functions are unable to complete.

I have an array of std::pairs which store my error codes along with their const char* error strings

std::pair<int, const char*> errorCodeArray[12] =
{ 
    std::pair<int,char*>(0,"Success"),
    std::pair<int,char*>(1,"Connection Error"),
    std::pair<int,char*>(2,"Request Timed Out"),
    // ..etc
};

If the errorcode is from WSAGetLastError() then I must use FormatMessage to get the error string as a LPWSTR, then convert it to a char*, I found this page:

How do I convert from LPCTSTR to std::string?

and tried this soultion which apparently works with LPCTSTR

int size = WideCharToMultiByte(CP_ACP, 0, errCode, -1, 0, 0, NULL, NULL);
char* buf = new char[size];
WideCharToMultiByte(CP_ACP, 0, errCode, -1, buf, size, NULL, NULL);
std::string str(buf);
delete[] buf;
return str.c_str();

but it doesn’t seem to work with LPWSTR, the result is always “???????????” and I don’t really understand character encoding enough to figure out a solution.

Can anyone shed some light on this? Thanks.

  • 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-31T06:24:50+00:00Added an answer on May 31, 2026 at 6:24 am

    FormatMessage() is provided as two functions:

    • FormatMessageA()
    • FormateMessageW()

    Use FormatMessageA() explicitly to avoid necessity for conversion.

    While this does not directly answer the question, it provides a solution by removing the requirement to convert from LPWSTR to a char*.

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

Sidebar

Related Questions

function showFields($selClient) { $result = mysql_query(SELECT * FROM project WHERE projectid = $selClient); $values
The C++ function definition is this __declspec(dllexport) LPWSTR __stdcall GetErrorString(int errCode); And I call
function getWriters(cat, lev, id) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome,
function get_total_adults() { $sql = SELECT SUM(number_adults_attending) as number_of_adults FROM is_nfo_rsvp; $result = mysql_query($sql)
function CloseWindow() { window.close(); } The above code is working fine for IE but
function t1() { echo 1; } function t2() { echo 2; } $funcs =
function randomString( len ) { // A random string of length 'len' made up
function now(){ return +new Date; } questions : what does the plus sign mean?
/************************************************************************** * * Function: toggleVis * * Description: Following Function hides and expands the
function icPageInit() { $(icImgDiv + icAlternate()).setOpacity(0); return true; } window.onload = icPageInit; This piece

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.