0

I have created a Dialog which it's derived from CDialog (MFC does this automatically), but I had to override the OnInitDialog method to make initialization of a ComboBox:

BOOL CLogin::OnInitDialog()
{
 CDialog::OnInitDialog();

 InitCommonControls();

 if ( FillInCombo() != 0 )
  //erro ao tentar ler leitoras
  return TRUE;

 return TRUE;
}

The method FillInCombo calls a PCSC class to fill this combo with all available smart card readers.

However, while debugging a strange behavior takes place. While attempting to select an item on the combo, it closes automatically (it actually generates an OnClose event) and DoModal returns -1.

Then, next, the application is never again loaded correctly unless I clean the solutions and build it again.

 CLogin SmartNetData;
 int ret = SmartNetData.DoModal();
 switch ( ret )
 {
    case IDOK:
    break;
    case -1: 
    // strange error
    OnOK();
    return TRUE;
    case IDABORT:
    case IDCANCEL:
    OnOK();
    return TRUE;
 };

Thanks for any possible help on this.

LATER EDIT: I realized the problem arises because of the combobox. I am not sure why. I replaced it by a ListBox and I am not getting troubles.

zlogdan
  • 279
  • 1
  • 6
  • 16

2 Answers2

2

I suspect some thing goes wrong in your OnInitDialog().

I suggest you to go for debug steps:
a) remove InitCommonControls() in OnInitDialog()
b) remove FillInCombo() in OnInitDialog()
c) remove InitCommonControls() and FillInCombo() in OnInitDialog()

After removing one by one, check with the DoModal returns value.

wengseng
  • 1,330
  • 1
  • 14
  • 27
  • Thanks for the help! I removed the FillinCombo function. I gave a lot of thought on this ( I read your answer yesterday night at home) and it looked like you were right, as this function calls a PCSC DLL and uses a std::vector but man I removed it and it still persists. I have removed the InitCommonControls function as unwind explained that it was not necessary at all. The method InitCommonControlsEx is alread called in the main class created by the MFC Wizard. – zlogdan Jan 12 '11 at 11:09
  • It is something within the code that VS 2005 generates for the combobox. Or something I missed . – zlogdan Jan 13 '11 at 14:47
0

I think you're doing InitCommonControls() in the wrong place. This should be done once in your program. It initializes the common controls library. Not the controls on your dialog themselves.

I typically put this in the app's startup routine, before bringing any windows up.

John Dibling
  • 99,718
  • 31
  • 186
  • 324