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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:42:59+00:00 2026-06-06T18:42:59+00:00

I am trying to display the contents of a listbox using the SendMessage function.

  • 0

I am trying to display the contents of a listbox using the SendMessage function. However when I press the button to execute the piece of code below, I get the following segfault in my code when I call

SendMessage(hwndLBox,LB_GETTEXT,k,(LPARAM)lBoxitems);

Segfault (dbgheap.c):

extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
        const void * pUserData
        )
 {
        if (!pUserData)
            return FALSE;

        if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
            return FALSE;

        return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}

The Code that causes this segfault:

            else if(LOWORD(wParam)==ID_BUTTON_CALC){

                int getLboxitems = SendMessage(hwndLBox,LB_GETCOUNT,NULL,NULL);

                char * lBoxitems = new char[getLboxitems];

                for(unsigned int k=0; k < getLboxitems; k++){
                        SendMessage(hwndLBox,LB_GETTEXT,k,(LPARAM)lBoxitems);
                        MessageBox(hwnd,lBoxitems,"Listbox says",NULL);
                }

                delete[] lBoxitems;
            }

I am using Visual Studio Beta 2011 to compile my code.

  • 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-06T18:43:01+00:00Added an answer on June 6, 2026 at 6:43 pm

    You need to allocate space for your strings. char * lBoxitems = new char[getLboxitems]; allocates a char array that is the size of how many items you have in the list.
    The following should work I think:

    else if(LOWORD(wParam)==ID_BUTTON_CALC)
    {
        int getLboxitems = SendMessage(hwndLBox, LB_GETCOUNT, NULL, NULL);
    
        char ** lBoxitems = new char*[getLboxitems];
    
        for(unsigned int k = 0; k < getLboxitems; k++)
        {
            int textlength = SendMessage(control, LB_GETTEXTLEN, (WPARAM)k, NULL);
            lBoxitems[k] = new char[textlength + 1]; // +1 for null terminator
            SendMessage(hwndLBox, LB_GETTEXT, (WPARAM)k, (LPARAM)lBoxitems[k]);
            MessageBox(hwnd, lBoxitems[k], "Listbox says" , NULL);
        }
        for (unsigned int k = 0; k < getLboxitems; k++)
        {
            delete [] lBoxitems[k];
        }
        delete[] lBoxitems;
    }
    

    However, using std::vector<std::vector<char>> or std::vector<std::string> would be easier:

    else if(LOWORD(wParam)==ID_BUTTON_CALC)
    {
        int getLboxitems = SendMessage(hwndLBox, LB_GETCOUNT, NULL, NULL);
    
        std::vector<std::string> v(getLboxitems);
    
        for(unsigned int k = 0; k < getLboxitems; k++)
        {
            int textlength = SendMessage(control, LB_GETTEXTLEN, (WPARAM)k, NULL);
            v[k].resize(textlength + 1);
            std::string& buff = v[k];
            SendMessage(hwndLBox, LB_GETTEXT, (WPARAM)k, (LPARAM)&buff[0]);
            MessageBox(hwnd, v[k].c_str(), "Listbox says" , NULL);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a DataGrid to display the contents of an object[][] .
I am trying to display a table in html page. However, the contents of
I am trying to display contents of a SQLite database in android. The code
I am trying to display the contents of a .cpp file in php. I
OK folks, I am trying to display the contents of a database table along
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm trying to display an svg graph with associated javascript in my application using
I'm new to Silverlight and I am trying to display the contents of a
If all I'm trying to do is display the contents of some web page
I'm trying to display the contents of a textarea, including any line breaks. var

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.