0

I am able to fix the bug I got but I am interested in the reason behind the bug.

I used my combo box (which was created using DDX mechanism) pointer as argument in one of my method.

For example:

bool CMyStuff::FillCombo(CComboBox* combo_ctrl)

But my combo box is generated by drag and drop, MFC by default created an object instead of pointer. As I required a pointer to send, I changed that member variable to a pointer.

But after this I got compilation error as DDX does not takes pointer as an input. So changed my DDX code from:

    DDX_Control(pDX, IDC_COMBO1, m_ptr_combo1);

to

    DDX_Control(pDX, IDC_COMBO1, *m_ptr_combo1);

Now application compiled successfully and when I launch my application the dialog has also shown properly. (Note: usually dialog will be shown at the center of the desktop but this time it shown at the left top corner).

Now when I drag my dialog or do anything, application is getting crashed.

When I changed this whole declaration and sent a reference instead of pointer, my application is working properly. Can anybody explain the reasons behind this behavior?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • 1
    Where does it crash ? Use the debugger to find out. Then edit your question and show us the relevant code. – Jabberwocky Apr 22 '16 at 09:13
  • Show at least the code where you call `FillCombo(CComboBox* combo_ctrl)`. – Jabberwocky Apr 22 '16 at 09:17
  • It is crashed inside app class. Where I initiate my Dialog. Debugger is not going inside dialog class even. Unfortunately there is not much code to show. But I will try to present as much code as possible to show. Thank you. – Bharadwaj Gali Apr 22 '16 at 09:30
  • 1
    If it crashes inside your app class, then it's interesting. The call stack is also interesting. Without more context and information it's hard to answer your question. You also should [read this](http://stackoverflow.com/help/mcve). – Jabberwocky Apr 22 '16 at 09:33
  • It seems to me you declared `m_combo_ptr` as a pointer inside your class and it should not be a pointer... How is it defined? – sergiol Jul 17 '16 at 01:05

0 Answers0