"Unsupported operation" error w/ a Spin Control?

I have a dialog-box app (using MS VC++ 5.0) that includes
a Spin Control (i.e. a "buddy" that should display the
numbers 1-4 and an up/down arrow control to its right).  While it works ok, when the app is first started I get an
error message saying "An unsupported operation was attempted."  After clicking OK, the app runs fine.  Debugging seems to point to the routine that gets called when the number in the box is changed (i.e. a variable that stores this value 1-4 just gets updated), yet I can't figure out what the problem is (= first time I've used this control).  It seems like it is an initialization problem, or perhaps I implemented the Spin incorrectly?

Can someone provide some sample code to show what this should look like?

Thanks in advance...
Who is Participating?
NullTerminatorConnect With a Mentor Commented:
"Unsupported Operation" is almost always a resource problem with the dialog.  Usually a mismatch between a resource id and its counterpart in your resource.h

Put a break point in DoDataExchange and step through it,  or when it asserts, open up the call stack window and drill back up to the line of code causing it in DoDataExchange.  The drill up is usually one line off of the actual execution point so look a line before or a line after.

Deleteing and replacing a control in a dialog is usually the culprit.  Corresponding calls to DDX_thisorthat need to be cleaned up as well.

Also check ' View Resource Symbols' for any unused symbols.  Check for instances of those unused symbols in your class cpp.

Guaranteed or your points back !
void CDlgPrd::DoDataExchange(CDataExchange* pDX)
      DDX_Control(pDX, IDC_SPIN2, m_spin2);
      DDX_Control(pDX, IDC_SPIN1, m_spin1);

BOOL CDlgPrd::OnInitDialog()
      // TODO: Add extra initialization here
      m_spin1.SetRange( 1, 250);
      m_spin2.SetRange( 1, 100 );
etc ...
Do you get the error message before or after your dialog box is shown?
Are you running the program on a 2nd computer or on the one you compiled and built it on?
It sounds to me like you have a conflict with your DLL and OCX version.

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

mconsidineAuthor Commented:

I get the error before the dialog box is opened.  And I am running it on the computer I developed the program on.  In fact, I get the error running it from Visual Studio.  In that case, I get an Assert error, with the option to Abort (to debug), Retry or Ignore.  If I hit
Ignore, the program continues fine (and all the results are correct, BTW).  If I go into Debug, then in one of the workspace windows there is a reference to the routine that is supposed to be called when the value changes.  I think it's fired off by EN_CHANGED or something like that (I'm not at the computer now...)  If more detail is helpful, I'll post more detail when I get to the computer this evening ...  
mconsidineAuthor Commented:
More detail:
  In the variable section for the dialog box class wizard :
    IDC_COMMSPIN               CSpinButtonCtrl m_commport
    IDC_COMMPORTVALUE  int                      m_commportvalue

  m_commport  is initialized in OnInitDialog this way :


  DoDataExchange looks like :
void CLunarGOTODlg::DoDataExchange(CDataExchange* pDX)

      DDX_Control(pDX, IDC_COMMSPIN, m_commport);
      DDX_Text(pDX, IDC_COMMPORTVALUE, m_commportvalue);
      DDV_MinMaxInt(pDX, m_commportvalue, 1, 6);

      ON_EN_CHANGE(IDC_COMMPORTVALUE, OnChangeCommportvalue)

  Under the message maps section, only       IDC_COMMPORTVALUE
has an enabled function - EN_CHANGE.  Selecting Edit Code
brings up :

void CLunarGOTODlg::OnChangeCommportvalue()
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the      CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the //control
// with the ENM_CHANGE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here

Is there a simpler way to get this value into a variable?

Basically, I want to be able to spin through comm port values
and set a variable to the comm port selected.

Since you are running the program from VS then it is unlikely that it is a DLL or OCX problem.  Since it happens before the dialog is opened then it is probably in your OnInitDialog.

I see one problem in your initialization which is probably causing your error.  If the code you posted is cut & pasted then your problem is in the call to CSpinButtonCtrl::SetBase(int Base).

The 'base' is either 10 for decimal or 16 for hex.  You have a 1.  Change that to a 10 and you should get rid of the error.  You wouldn't get a compile time error because the function accepts an int value.

Try that out and let me know...

mconsidineAuthor Commented:
Well that looks like it did it : Both deleting the SetBase and
setting it to 10 result in no error.  Is the default decimal?  Looks
like the points are yours!
mconsidineAuthor Commented:
Ok, I guess I jumped the gun....

Even though I made the change suggested above, when I
reboot the machine and run the program again (this time
from the command line and not from inside VS) I get an
assertion error (debug assertion?).  The program then continues
along correctly.  If I quick the program and restart it, I *don't*
get the error and the program continues along correctly.

Any thoughts???
Make sure you recompile both the Release and Debug version.  You should only run the Release version from outside the Visual Studio.  If you still have the problem, debug the code from inside the beginning of the OnInitDialog function and see if you can track down the assertion error.

Did you use the Studio wizard to create the application?

I really can't help unless I see the code or know exactly what kind of assertion error you are getting.

Let me know.... J.R.
mconsidineAuthor Commented:
Thanks for your comments.  This is what happens when I
recompile both Debug and Release versions :
    Release version run from outside of VS :
      Error : An unsupported operation was attempted.
      {program then continues fine - this is what has been
    Debug version run from outside of VS :
      Debug assertion failed!  {file is dlgdata.cpp in                     ...\vc\mfc\src...}
      "Retry" to debug gets me exception 03H in MFC42D.DLL
I'll reboot the machine and try debug mode in VS again.  {The
error only comes up the first time you run it unless the machine
shut down and restarted again ...  I must be doing something
real stupid ....}

Does this help, or is there different info I can post?

When you get the Debug assertion error:
file is dlgdata.cpp in ...
It should be giving a line number.  If you click Debug it should take you to the line number, if you could post the code at the line number plus a few lines above and below, we can probably work through it.

In the mean time...do a search for files named
mfc42.dll & mfc42d.dll
There should be a version in your C:\windows\system directory and there may be a stray version somewhere else that may be interfering.  If you find more than one version, make sure the most recent version is in the C:\windows\system directory...

Try that and take a look at the assertion error line (post it as I described above..)

mconsidineAuthor Commented:
When I debug this, I get pointed to the following (line 43) :

HWND CDataExchange::PrepareCtrl(int nIDC)
      ASSERT(nIDC != 0);
      ASSERT(nIDC != -1); // not allowed
      HWND hWndCtrl;
      m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
      if (hWndCtrl == NULL)
            TRACE1("Error: no data exchange control                                    with ID 0x%04X.\n", nIDC);
----->>>>            ASSERT(FALSE);
      m_hWndLastControl = hWndCtrl;
      m_bEditLastControl = FALSE; // not an edit item by                          default
      ASSERT(hWndCtrl != NULL);   // never return NULL                           handle
      return hWndCtrl;

I've arrowed the line it points to ...

The call stack window shows :

CDataExchange::PrepareCtrl(int 1075) line 43 + 25 bytes
DDX_Control(CDataExchange * 0x0067f04c, int 1075, CWnd & {CWnd hWnd=0x00000000}) line 577 + 12 bytes
CLunarGOTODlg::DoDataExchange(CDataExchange * 0x0067f04c) line 2279
CWnd::UpdateData(int 0) line 3144
CLunarGOTODlg::OnChangeCommportvalue() line 2848
DispatchCmdMsg(CCmdTarget * 0x0067fc00 {CLunarGOTODlg}, unsigned int 1026, int 768, void (void)* 0x00402e3f CLunarGOTODlg::OnChangeCommportvalue(void), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 1026, int 768, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 301 + 39 bytes
CDialog::OnCmdMsg(unsigned int 1026, int 768, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 96 + 24 bytes
CWnd::OnCommand(unsigned int 50332674, long 1204) line 2058

There are other versions of MFC42xxx but the most recent are
in the Windows\System subdirectory...

Could I have a compiler setting wrong??

CWnd::OnWndMsg(unsigned int 273, unsigned int 50332674, long 1204, long * 0x0067f2c4) line 1567 + 28 bytes
CWnd::WindowProc(unsigned int 273, unsigned int 50332674, long 1204) line 1555 + 30 bytes
AfxCallWndProc(CWnd * 0x0067fc00 {CLunarGOTODlg hWnd=???}, HWND__ * 0x000004ac, unsigned int 273, unsigned int 50332674, long 1204) line 217 + 26 bytes
AfxWndProc(HWND__ * 0x000004ac, unsigned int 273, unsigned int 50332674, long 1204) line 371
AfxWndProcBase(HWND__ * 0x000004ac, unsigned int 273, unsigned int 50332674, long 1204) line 203 + 21 bytes
KERNEL32! bff735d9()
KERNEL32! bff9222f()
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.

All Courses

From novice to tech pro — start learning today.