• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1169
  • Last Modified:

DDX_Control - valid arguments?

I have a fairly complicated dialog that I need to map/unmap sets of controls.  I didn't want to have 30+ control variables running around, so I thought I would organize things in a structure.  So, in my DataExchange method, after the AFX wrappers, I have:

         DDX_Control(pDX, IDC_A_11_STATIC, m_BankA.cGunType[0].cLabels[0]);
         DDX_Control(pDX, IDC_A_12_STATIC, m_BankA.cGunType[0].cLabels[1]);
         DDX_Control(pDX, IDC_A_13_STATIC, m_BankA.cGunType[0].cLabels[2]);

the above is a code snippet - compiles fine.  The .cLabels[n] reference a custom activeX control.  Looking at this code, I would think that I have something equivalent to :

         DDX_Control(pDX, IDC_A_11_STATIC, m_cLabels[0]);  // example

However, using the structure notion results in an assertion violation, while the array reference does not.

Today's question is - why?  Both code snippets decompose to the same discrete variable location, or so I think...
What am I missing?
  • 5
  • 3
1 Solution
AndyAinscowFreelance programmer / ConsultantCommented:
What is missing? - support from the IDE for this second method.  What the DDX tries to do is assign ONE variable to ONE control.  You get the assert as the variable doesn't make sense for the assignment.

What you can do for the DDX routine (IF the control ID's are incremented by one) is have it in a loop

for(int i = 0; i < 3; i++)
  DDX_Control(pDX, IDC_A_11_STATIC+i, m_BankA.cGunType[0].cLabels[i]);
charles_gilleyAuthor Commented:

  How is your method different from mine other than you are using a loop, and I unrolled mine?
I'm coding this by hand, so I don't care about the IDE at all.  I'm just wondering about the structure
reference of the control.....

Sorry to be dense...
AndyAinscowFreelance programmer / ConsultantCommented:
I may not of understood you.
I thought you were attempting a shortcut where you expected the DDX to 'know' how large the array was and automatically assign variables to the controls until the end of the array was reached.

What ASSERT do you get?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

charles_gilleyAuthor Commented:
Nope - been there, done that, have the t-shirt :).  That's a newbie mfc question, and I'm just about 12" above newbie status... ;)

Here's the real code snippet:

      DDX_Control(pDX, IDC_PS_TYPE_STATIC, m_cPowerSupplyStatic);
      DDX_Control(pDX, IDC_TITLE_STATIC, m_cTitleStatic);

         //DDX_Control(pDX, IDC_BANK_A_GBOX, m_BankA.cGroupBox);

         // Gun 1:

         DDX_Control(pDX, IDC_A1_DEVICE_BTN, m_BankA.cGunType[0].cDeviceTypeBtn);

A couple of notes.  First, the AFX_DATA_MAP is the typical area added by the IDE.  Note the standard single control variable passed into DDX_Control.  Works fine.

Now, after the last comment - this DDX_Control statement is added manually and is misbehaving.  The cDeviceTypeBtn is defined as a control, it all compiles, but when it executes I get an access violation (C0000005) inside of SubclassWindow.  I'm going to do more testing...
AndyAinscowFreelance programmer / ConsultantCommented:
Is m_BankA.cGunType[0].cDeviceTypeBtn valid?
Step into the DDX_Control function and find the line asserting.
charles_gilleyAuthor Commented:
I believe so.  I step into the DDX_Exchange code... we make it all the way into the SubclassWindow call and crater at PreSubclassWindow();  Just walked through the execution for a standard single control - looks the same as the other.  

fwiw, I've duplicated this behavior with my controls (custom activeX) and standard CButton controls, so I don't think I have anything weird in this area.

Wait a minute... the address displayed by the debugger in EVC++ says 0x000000 for the function.  Hmmmm...
charles_gilleyAuthor Commented:
Okay, I've got a class problem / inheritance issue.  When I create a structure and possibly an array, I've got a null pointer around for this virtual function.
charles_gilleyAuthor Commented:
Whoops, forgot about this one.  Apologies to one and all... Andy, thanks for your help and suggestions. points to you...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now