Solved

"Unsupported operation" error w/ a Spin Control?

Posted on 1998-11-24
12
1,315 Views
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...
0
Comment
Question by:mconsidine
12 Comments
 
LVL 2

Expert Comment

by:AlFa
ID: 1178536
void CDlgPrd::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CDlgPrd)
      DDX_Control(pDX, IDC_SPIN2, m_spin2);
      DDX_Control(pDX, IDC_SPIN1, m_spin1);
etc...

BOOL CDlgPrd::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      // TODO: Add extra initialization here
      m_spin1.SetRange( 1, 250);
      m_spin2.SetRange( 1, 100 );
etc ...
0
 
LVL 2

Expert Comment

by:jrmcg
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.

J.R.
0
 

Author Comment

by:mconsidine
ID: 1178538
Hi,

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 ...  
Matt
0
 

Author Comment

by:mconsidine
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 :

      m_commport.SetRange(1,6);
      m_commport.SetBase(1);

  DoDataExchange looks like :
void CLunarGOTODlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CLunarGOTODlg)

      DDX_Control(pDX, IDC_COMMSPIN, m_commport);
.      
      DDX_Text(pDX, IDC_COMMPORTVALUE, m_commportvalue);
      DDV_MinMaxInt(pDX, m_commportvalue, 1, 6);
.
      //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLunarGOTODlg, CDialog)
      //{{AFX_MSG_MAP(CLunarGOTODlg)
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_WM_CLOSE()
      ON_BN_CLICKED(IDGOTO, OnGoto)
      ON_BN_CLICKED(IDC_CHECKPORT, OnCheckport)
      ON_EN_CHANGE(IDC_COMMPORTVALUE, OnChangeCommportvalue)
      ON_WM_CREATE()
.

  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
  UpdateData(FALSE);
}

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.

0
 
LVL 2

Expert Comment

by:jrmcg
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...

Regards,
J.R.
0
 

Author Comment

by:mconsidine
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!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mconsidine
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???
Matt
0
 
LVL 2

Expert Comment

by:jrmcg
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.
0
 

Author Comment

by:mconsidine
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
        happening...}
    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?

Thanks,
Matt
0
 
LVL 2

Expert Comment

by:jrmcg
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 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..)

J.R.
0
 

Author Comment

by:mconsidine
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);
            AfxThrowNotSupportedException();
      }
      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??

Matt
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()
0
 
LVL 3

Accepted Solution

by:
NullTerminator earned 70 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 !
Null
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now