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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:25:33+00:00 2026-05-23T01:25:33+00:00

I need to append text to win32 edit control i have working function to

  • 0

I need to append text to win32 edit control i have working function to do this , but the text that printed in the edit control is gibrish why ?
the sample code taken from microsoft example from here

void settext(HWND hDlg,std::string s)
{
    //std::wstring ws; 
    //ws.assign( s.begin(), s.end() );
    //LPWSTR pwst = &ws[0];
    //// get temporary LPCWSTR (pretty safe)
    //LPCWSTR pcwstr = ws.c_str();
    //SetDlgItemText(hWndEdit, IDC_EDIT1,pcwstr);
    HWND hWndEdit = GetDlgItem (hDlg, IDC_EDIT1);
    LPSTR pst = &s[0];
    int ndx = GetWindowTextLength (hWndEdit);
    SetFocus (hWndEdit);
    #ifdef WIN32
      SendMessage (hWndEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
    #else
      SendMessage (hWndEdit, EM_SETSEL, 0, MAKELONG (ndx, ndx));
    #endif
      SendMessage (hWndEdit, EM_REPLACESEL,0,(LPARAM)pst);
    
}

and from the DlgProc im calling :

std::string  ss("wwwwww");
settext(hwnd,ss);

update
even if i do as suggested here :

 SendMessage (hWndEdit, EM_REPLACESEL,0,(LPARAM)s.c_str()); 

that pass compilation but still the characters printed are gibrish
and if i do :

LPSTR pst = s.c_str()

it doesn’t pass compilation the error:
error C2440: ‘initializing’ : cannot convert from ‘const char *’ to ‘LPSTR’

  • 1 1 Answer
  • 1 View
  • 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-23T01:25:35+00:00Added an answer on May 23, 2026 at 1:25 am

    My guess is that your app is compiled for Unicode and so the window is interpreting your ANSI C string as a Unicode C string, hence the characters from another language.

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

Sidebar

Related Questions

I need to edit file , the main issue is to append text between
HTML is <a>ref</a> I need to get <a>ref</a>text How can i do this? $('a').append('text')
$('h2').each(function() { $('UL.chapters_list').append($('<li/>', {text: $(this).text()})) }); This code grabs all of the <H2> tags
I have several projects where I need to append strings to a BSTR/CComBSTR/_bstr_t object
Need a function that takes a character as a parameter and returns true if
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I need to append text repeatedly to an existing file in Java. How do
I need to append some text to an input field...
Good day. I found the example below, I need to append some more text
I have a string for example like :)text :)text:) :-) word :-( i need

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.