Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


"Unsupported operation" error w/ a Spin Control?

Posted on 1998-11-24
Medium Priority
Last Modified: 2012-06-27
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...
Question by:mconsidine
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1178536
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 ...

Expert Comment

ID: 1178537
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.


Author Comment

ID: 1178538

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 ...  
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 1178539
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.


Expert Comment

ID: 1178540
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...


Author Comment

ID: 1178541
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!

Author Comment

ID: 1178542
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???

Expert Comment

ID: 1178543
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.

Author Comment

ID: 1178544
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?


Expert Comment

ID: 1178545
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 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..)


Author Comment

ID: 1178546
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()

Accepted Solution

NullTerminator earned 140 total points
ID: 1178547
"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 !

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question