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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:25+00:00 2026-05-25T22:26:25+00:00

EDIT: Working code posted below, nonworking code commented out. You must use the same

  • 0

EDIT: Working code posted below, nonworking code commented out. You must use the same CHAR_T for retrieving data from windows as you used to create them in Win7.

I have a dialog written in C that works perfectly in WinXP but fails to collect user input from an edit control in unicode in Win7. The problem occurs on the first call to SendMessageW as shown below:

/* handles to controls */
HWND hDomainEdit;
HWND hOtherEdit;
HWND hTextOut;
HWND hButton;
/* buffers to receive input */
WCHAR wszDomain[256];
CHAR szOtherInput[512];
CHAR szBuffer[512]; //added to hold temporary value of wszDomain
/* a test string */
const CHAR szTest[] = "This is a test of SendMessageA."

BOOL dialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {

    if (message == WM_INIT) {
        /* get all the handles shown above, then... */
        SendMessageA(hTextOut, WM_SETTEXT, 0, (LPARAM) szTest);
        /* worked fine */
        /* do a few other things */
    } else if (message == WM_COMMAND) {
        /* are some other conditions are true?  they sure are */
        /* time to collect a bunch of input from controls */
        int cchResultLen = (int) SendMessageA(hOtherEdit, WM_GETTEXT, 512, (LPARAM) szOtherInput);
        /* cchResultLen is correctly the length of the user input */
        /* cchResultLen = (int) SendMessageW(hDomainEdit, WM_GETTEXT, 256, (LPARAM) wszDomain); */
        /* begin new code */
        cchResultLen = (int) SendMessageA(hDomainEdit, WM_GETTEXT, 512, (LPARAM) szBuffer);
        cchResultLen = MultiByteToWideChar(CP_UTF8, 0, szBuffer, cchResultLen, wszDomain, 256);
        wszDomain[cchResultLen] = 0; /* above doesn't terminate string */
        /* after SendMessageW(), cchResultLen was 0, no string transferred, no error
           message.  using SendMessageA, all is well. */
    }
}

It appears SendMessageA works multiple times with message = WM_GETTEXT or WM_SETTEXT, and suddenly, when a wide string is required, SendMessageW fails. Now, I know everyone is thinking that you should pick a CHAR_T and stick with it by always using SendMessage, but it’s not so; Win32.hlp explicitly notes that it’s possible to use both in the same program by calling the individual functions manually. I’m sure someone else is ready to say that the control itself is or becomes committed to one particular CHAR_T, but that’s not the case in WinXP, where this worked perfectly. That particular edit control is also never set to an ASCII string explicitly.

The program interacts with WinHttp, which requires all WCHAR strings, and that’s where the SendMessageW comes in. The rest of the inputs are only used internally and are primarily parsed integers with unit labels, which are more convenient and efficient in ASCII, if for no other reason than because the program was originally written that way.

So what do? Have they really changed something as integral as SendMessage to be incompatible? If so, is it a known bug with a work around, or is the ability to switch CHAR_T at will a deprecated feature? Is there some other easier way than expanding the input to WCHAR manually after getting it with SendMessageA?

  • 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-25T22:26:26+00:00Added an answer on May 25, 2026 at 10:26 pm

    All window handles were fine. The folks at MSDN informed me that any window created with an ‘A’ function – in this case DialogBoxParamA() – must be accessed via the ‘A’ functions. As for the fact that it worked in XP, they said “Just because it works doesn’t mean it’s right”. I suppose that functionality was deprecated – would have been nice to hear about that before it stopped working!

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

Sidebar

Related Questions

EDIT: See my working code in the answers below. In brief: I have a
I won't want to have edit any working sets. I just want a way
im using the WPFToolkit's DataGrid and im trying to get an edit button working,
I'm trying to get edit-and-continue working with Visual Studio 2008 with an ASP.Net MVC
I'm working on a system were a user can edit existing objects (Filter domain
EDIT: I have edited my post... Working on a project (c#), I have a
i'm working with TFS and i need to edit file localy without checking it
I have recently been working with Python using Komodo Edit and other simpler editors
I'm working in Visual Studio 2008 and I would like for Edit > Outlining
I am working on a small team of web application developers. We edit JSPs

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.