Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Win32: l need help on filling a combo box [Solved]

Win32: l need help on filling a combo box [Solved]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12105981
    wrote on last edited by
    #1

    Am creating application and l need to fill a combo box list. However, l was able to do all and is working but whenever l filling the last combobox, l get an exception as below.

    First-chance exception at 0x7789dba9 in Unical PTUME.exe: 0xC0000005: Access violation reading location 0x00000001.
    Unhandled exception at 0x7789dba9 in Unical PTUME.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

    What does it mean and how can l correct it?

    code snippet below:

    case WM_CREATE:
    DialogBox(((LPCREATESTRUCT)lParam)->hInstance, MAKEINTRESOURCE(IDD_CHOICEBOX),hWnd,choicedlg);//Dialog proc.
    return 0;

    INT_PTR CALLBACK choicedlg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    int i=0; static int firsttime=1; PWSTR input=NULL;
    switch(message)
    {
    case WM_INITDIALOG:
    //Add faculties to the combo list
    for(i=0; i<=sizeof(Choice)/sizeof(Choice[0]); i++){
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_FACULTY,CB_ADDSTRING,0,(LPARAM)Choice[i]);
    }
    for(i=0; i<=sizeof(Course)/sizeof(Course[0]); i++){
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT1,CB_ADDSTRING,0,(LPARAM)Course[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT2,CB_ADDSTRING,0,(LPARAM)Course[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT3,CB_ADDSTRING,0,(LPARAM)Course[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT4,CB_ADDSTRING,0,(LPARAM)Course[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT5,CB_ADDSTRING,0,(LPARAM)Course[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT6,CB_ADDSTRING,0,(LPARAM)Course[i]);
    }
    for(i=0; i<=sizeof(Year)/sizeof(Year[0]); i++){
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR1,CB_ADDSTRING,0,(LPARAM)Year[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR2,CB_ADDSTRING,0,(LPARAM)Year[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR3,CB_ADDSTRING,0,(LPARAM)Year[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR4,CB_ADDSTRING,0,(LPARAM)Year[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR5,CB_ADDSTRING,0,(LPARAM)Year[i]);
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR6,CB_ADDSTRING,0,(LPARAM)Year[i]);
    } //etc
    However, if l add the code below, l always get error message as above.

    for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++){
    SendDlgItemMessage(hwnd,IDC_UNICALPTUME_TIME,CB_ADDSTRING,0,(LPARAM)Time[i]);
    }// problem code

    Richard Andrew x64R J 2 Replies Last reply
    0
    • U User 12105981

      Am creating application and l need to fill a combo box list. However, l was able to do all and is working but whenever l filling the last combobox, l get an exception as below.

      First-chance exception at 0x7789dba9 in Unical PTUME.exe: 0xC0000005: Access violation reading location 0x00000001.
      Unhandled exception at 0x7789dba9 in Unical PTUME.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

      What does it mean and how can l correct it?

      code snippet below:

      case WM_CREATE:
      DialogBox(((LPCREATESTRUCT)lParam)->hInstance, MAKEINTRESOURCE(IDD_CHOICEBOX),hWnd,choicedlg);//Dialog proc.
      return 0;

      INT_PTR CALLBACK choicedlg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
      int i=0; static int firsttime=1; PWSTR input=NULL;
      switch(message)
      {
      case WM_INITDIALOG:
      //Add faculties to the combo list
      for(i=0; i<=sizeof(Choice)/sizeof(Choice[0]); i++){
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_FACULTY,CB_ADDSTRING,0,(LPARAM)Choice[i]);
      }
      for(i=0; i<=sizeof(Course)/sizeof(Course[0]); i++){
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT1,CB_ADDSTRING,0,(LPARAM)Course[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT2,CB_ADDSTRING,0,(LPARAM)Course[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT3,CB_ADDSTRING,0,(LPARAM)Course[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT4,CB_ADDSTRING,0,(LPARAM)Course[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT5,CB_ADDSTRING,0,(LPARAM)Course[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT6,CB_ADDSTRING,0,(LPARAM)Course[i]);
      }
      for(i=0; i<=sizeof(Year)/sizeof(Year[0]); i++){
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR1,CB_ADDSTRING,0,(LPARAM)Year[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR2,CB_ADDSTRING,0,(LPARAM)Year[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR3,CB_ADDSTRING,0,(LPARAM)Year[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR4,CB_ADDSTRING,0,(LPARAM)Year[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR5,CB_ADDSTRING,0,(LPARAM)Year[i]);
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR6,CB_ADDSTRING,0,(LPARAM)Year[i]);
      } //etc
      However, if l add the code below, l always get error message as above.

      for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++){
      SendDlgItemMessage(hwnd,IDC_UNICALPTUME_TIME,CB_ADDSTRING,0,(LPARAM)Time[i]);
      }// problem code

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      What is the value of Time[i] when the code runs?

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • U User 12105981

        Am creating application and l need to fill a combo box list. However, l was able to do all and is working but whenever l filling the last combobox, l get an exception as below.

        First-chance exception at 0x7789dba9 in Unical PTUME.exe: 0xC0000005: Access violation reading location 0x00000001.
        Unhandled exception at 0x7789dba9 in Unical PTUME.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

        What does it mean and how can l correct it?

        code snippet below:

        case WM_CREATE:
        DialogBox(((LPCREATESTRUCT)lParam)->hInstance, MAKEINTRESOURCE(IDD_CHOICEBOX),hWnd,choicedlg);//Dialog proc.
        return 0;

        INT_PTR CALLBACK choicedlg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
        int i=0; static int firsttime=1; PWSTR input=NULL;
        switch(message)
        {
        case WM_INITDIALOG:
        //Add faculties to the combo list
        for(i=0; i<=sizeof(Choice)/sizeof(Choice[0]); i++){
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_FACULTY,CB_ADDSTRING,0,(LPARAM)Choice[i]);
        }
        for(i=0; i<=sizeof(Course)/sizeof(Course[0]); i++){
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT1,CB_ADDSTRING,0,(LPARAM)Course[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT2,CB_ADDSTRING,0,(LPARAM)Course[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT3,CB_ADDSTRING,0,(LPARAM)Course[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT4,CB_ADDSTRING,0,(LPARAM)Course[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT5,CB_ADDSTRING,0,(LPARAM)Course[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT6,CB_ADDSTRING,0,(LPARAM)Course[i]);
        }
        for(i=0; i<=sizeof(Year)/sizeof(Year[0]); i++){
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR1,CB_ADDSTRING,0,(LPARAM)Year[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR2,CB_ADDSTRING,0,(LPARAM)Year[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR3,CB_ADDSTRING,0,(LPARAM)Year[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR4,CB_ADDSTRING,0,(LPARAM)Year[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR5,CB_ADDSTRING,0,(LPARAM)Year[i]);
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR6,CB_ADDSTRING,0,(LPARAM)Year[i]);
        } //etc
        However, if l add the code below, l always get error message as above.

        for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++){
        SendDlgItemMessage(hwnd,IDC_UNICALPTUME_TIME,CB_ADDSTRING,0,(LPARAM)Time[i]);
        }// problem code

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        All your for loops are iterating from 0 to (including) sizeof(array)/sizeof(array[0]):

        for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++)

        So they will access one item behind the array size with the last iteration because the max. allowed index is the number of items minus one. Change all your loops to use < rather than <= (here for the last one):

        for(i=0; i<sizeof(Time)/sizeof(Time[0]); i++)

        U 1 Reply Last reply
        0
        • J Jochen Arndt

          All your for loops are iterating from 0 to (including) sizeof(array)/sizeof(array[0]):

          for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++)

          So they will access one item behind the array size with the last iteration because the max. allowed index is the number of items minus one. Change all your loops to use < rather than <= (here for the last one):

          for(i=0; i<sizeof(Time)/sizeof(Time[0]); i++)

          U Offline
          U Offline
          User 12105981
          wrote on last edited by
          #4

          @Jochenn Thanks, l made the corrections and it worked.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups