Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Class Creation Problem

Class Creation Problem

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiodebugginghelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Like2Byte
    wrote on last edited by
    #1

    Hi, I'm working in MFC using VS 2003.net in UNMANAGED code - MFC (not .NET). I've a class. It has two constructors.

    typedef enum calibDataType_e
    {
    CDT_UNKNOWN_E = 0,
    CDT_REGISTER_E,
    CDT_END_E /*Keep as last*/
    } calibDataType_t;

    //the class
    class CCalibEntry : public CDialog
    {
    public:
    CString csLabel;
    CString csValue;
    float fValue;
    enum { IDD = IDD_VALUEENTRY };
    public:
    CCalibEntry(CString csLabel, CWnd* pParent = NULL);
    CCalibEntry(CString csLabel, calibDataType_t pt = CDT_UNKNOWN_E, CWnd* pParent = NULL);
    protected:
    bool IsValidEntry();
    bool ValidateRegisterEntry();
    virtual BOOL OnInitDialog();
    virtual void OnOK();
    afx_msg void OnDestroy( );
    DECLARE_MESSAGE_MAP()
    private:
    int dataType;
    };

    //The constructors. Note the differing constructor signatures
    CCalibEntry::CCalibEntry (CString csLabel, CWnd *pParent) : CDialog (IDD, pParent), dataType(CDT_UNKNOWN_E)
    {
    this->csLabel = csLabel;
    }

    CCalibEntry::CCalibEntry (CString csLabel, calibDataType_t dt, CWnd *pParent) : CDialog (IDD, pParent)
    {
    this->csLabel = csLabel;
    dataType = dt;

    if( dataType == CDT_REGISTER_E )
    {
    //provide a hint to the user
    csValue = _T("0.0.0");
    }
    }

    When this code is called via: CCalibEntry dlg ( message, CDT_REGISTER_E, this ); It enters BOTH constructors. (Whereas, as I understand it, it should only enter: "CCalibEntry::CCalibEntry (CString csLabel, calibDataType_t dt, CWnd *pParent) : CDialog (IDD, pParent)" Oddly enough, it also enters OnInitDialog *after* the user presses the 'OK' key.:mad: W...T...H? 1) Isn't just the constructor with the matching signature the *ONLY* constructor to be entered? I've cleaned by project and rebuild from scratch, pulled from source control & rebuilt again, deleted NCB files. 2) Also, setting breakpoints in the second contructor code at, say, the top line ("this->csLabel = csLabel;") results in the breakpoint being *moved* to the line with the comment ("//provide a hint to the user") -- as if the comment line is going to execute some code. Thoughts? Signed, Frustrated! :wtf:

    M 1 Reply Last reply
    0
    • L Like2Byte

      Hi, I'm working in MFC using VS 2003.net in UNMANAGED code - MFC (not .NET). I've a class. It has two constructors.

      typedef enum calibDataType_e
      {
      CDT_UNKNOWN_E = 0,
      CDT_REGISTER_E,
      CDT_END_E /*Keep as last*/
      } calibDataType_t;

      //the class
      class CCalibEntry : public CDialog
      {
      public:
      CString csLabel;
      CString csValue;
      float fValue;
      enum { IDD = IDD_VALUEENTRY };
      public:
      CCalibEntry(CString csLabel, CWnd* pParent = NULL);
      CCalibEntry(CString csLabel, calibDataType_t pt = CDT_UNKNOWN_E, CWnd* pParent = NULL);
      protected:
      bool IsValidEntry();
      bool ValidateRegisterEntry();
      virtual BOOL OnInitDialog();
      virtual void OnOK();
      afx_msg void OnDestroy( );
      DECLARE_MESSAGE_MAP()
      private:
      int dataType;
      };

      //The constructors. Note the differing constructor signatures
      CCalibEntry::CCalibEntry (CString csLabel, CWnd *pParent) : CDialog (IDD, pParent), dataType(CDT_UNKNOWN_E)
      {
      this->csLabel = csLabel;
      }

      CCalibEntry::CCalibEntry (CString csLabel, calibDataType_t dt, CWnd *pParent) : CDialog (IDD, pParent)
      {
      this->csLabel = csLabel;
      dataType = dt;

      if( dataType == CDT_REGISTER_E )
      {
      //provide a hint to the user
      csValue = _T("0.0.0");
      }
      }

      When this code is called via: CCalibEntry dlg ( message, CDT_REGISTER_E, this ); It enters BOTH constructors. (Whereas, as I understand it, it should only enter: "CCalibEntry::CCalibEntry (CString csLabel, calibDataType_t dt, CWnd *pParent) : CDialog (IDD, pParent)" Oddly enough, it also enters OnInitDialog *after* the user presses the 'OK' key.:mad: W...T...H? 1) Isn't just the constructor with the matching signature the *ONLY* constructor to be entered? I've cleaned by project and rebuild from scratch, pulled from source control & rebuilt again, deleted NCB files. 2) Also, setting breakpoints in the second contructor code at, say, the top line ("this->csLabel = csLabel;") results in the breakpoint being *moved* to the line with the comment ("//provide a hint to the user") -- as if the comment line is going to execute some code. Thoughts? Signed, Frustrated! :wtf:

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Are all compiler optimizations turned off? Those constructors are similar enough where the compiler may have rearranged the code.

      Like2Byte wrote:

      Oddly enough, it also enters OnInitDialog *after* the user presses the 'OK' key.

      Not sure what class' OnInitDialog() you're referring to or where/how this dialog gets created... Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      L 1 Reply Last reply
      0
      • M Mark Salsbery

        Are all compiler optimizations turned off? Those constructors are similar enough where the compiler may have rearranged the code.

        Like2Byte wrote:

        Oddly enough, it also enters OnInitDialog *after* the user presses the 'OK' key.

        Not sure what class' OnInitDialog() you're referring to or where/how this dialog gets created... Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        L Offline
        L Offline
        Like2Byte
        wrote on last edited by
        #3

        OnInitDialog() is derived from the Base class CDialog. It's used to do any special initialization required to display the form. For instance, if you have a dropdown(DD) controlling two groups of radio buttons. Item0 in the DD displays the left hand radio buttons hides the right hand; while, item1 in the DD displays the RHS and hides the LHS. http://msdn.microsoft.com/en-us/library/fwz35s59(VS.80).aspx It's supposed to perform these operations BEFORE the form is displayed - in my instance, the code there is being executed AFTER I press OnOK(). It's gotta be some stale OBJ code in the project I'm working on that's causing it to refer to the wrong address locations. Anyone else have a similar experience?

        M 1 Reply Last reply
        0
        • L Like2Byte

          OnInitDialog() is derived from the Base class CDialog. It's used to do any special initialization required to display the form. For instance, if you have a dropdown(DD) controlling two groups of radio buttons. Item0 in the DD displays the left hand radio buttons hides the right hand; while, item1 in the DD displays the RHS and hides the LHS. http://msdn.microsoft.com/en-us/library/fwz35s59(VS.80).aspx It's supposed to perform these operations BEFORE the form is displayed - in my instance, the code there is being executed AFTER I press OnOK(). It's gotta be some stale OBJ code in the project I'm working on that's causing it to refer to the wrong address locations. Anyone else have a similar experience?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Right, I know how the method works. My point was, I couldn't tell from the code you posted which dialog class you were referring to, or how and where you are creating the dialog. The system sends the WM_INITDIALOG message before the dialog is displayed so it shouldn't be related to your code. Do you have corrupt or outdated debug info hanging around somewhere? Have you cleaned the project's intermediate and output files by hand before a full rebuild? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          L 1 Reply Last reply
          0
          • M Mark Salsbery

            Right, I know how the method works. My point was, I couldn't tell from the code you posted which dialog class you were referring to, or how and where you are creating the dialog. The system sends the WM_INITDIALOG message before the dialog is displayed so it shouldn't be related to your code. Do you have corrupt or outdated debug info hanging around somewhere? Have you cleaned the project's intermediate and output files by hand before a full rebuild? Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            L Offline
            L Offline
            Like2Byte
            wrote on last edited by
            #5

            OK, sorry. Misunderstood you there. Do you have corrupt or outdated debug info hanging around somewhere? That's been my theory all along. It's strange because I cleared all objs by hand yesterday. I was just able to get it to clean up. There's something majorly wrong with the project I'm working in. I actually tried all those methods: Deleted OBJs by hand, performed "Clean Solution", Compile each project singularly via the solution explorer, 'Re-build', etc. What I finally did was go directly to the offending file, select it and click 'Compile.' Then I right clicked on the project the file is a part of and did a "Build". Then I did a "Build Solution", debug 'Start' and performed the operations. Problem solved. There's definitely a problem with the project settings if all files are not kept up to date WRT edit times vs compile times.

            M 1 Reply Last reply
            0
            • L Like2Byte

              OK, sorry. Misunderstood you there. Do you have corrupt or outdated debug info hanging around somewhere? That's been my theory all along. It's strange because I cleared all objs by hand yesterday. I was just able to get it to clean up. There's something majorly wrong with the project I'm working in. I actually tried all those methods: Deleted OBJs by hand, performed "Clean Solution", Compile each project singularly via the solution explorer, 'Re-build', etc. What I finally did was go directly to the offending file, select it and click 'Compile.' Then I right clicked on the project the file is a part of and did a "Build". Then I did a "Build Solution", debug 'Start' and performed the operations. Problem solved. There's definitely a problem with the project settings if all files are not kept up to date WRT edit times vs compile times.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Cool thanks for the update! I know I've had a similar problem in the past - I think I gave up and re-created the project from scratch. It hasn't happened since VS 2003 for me thankfully :) Cheers, Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups