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. Cdialog CWnd* pParent null after passing this pointer to Cdialog constructer

Cdialog CWnd* pParent null after passing this pointer to Cdialog constructer

Scheduled Pinned Locked Moved C / C++ / MFC
debugging
4 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    I have a modeless dialog from which I display to two modal dialog boxes one after the other I would like to save all the information I get from the two in the modeless dialog So my plan was when creating the modal dialog box pass the Cwnd pointer using the this pointer Well the first one seems to work by this I mean make breakpoint

    abendialog = new RTMDialog(mylparam,this);

    at the creation of the object and then at the contructor

    RTMDialog::RTMDialog(LPARAM mylparam, CWnd* pParent)
    : CDialog(IDD_DIALOG9, pParent)

    at this pParent has valid pointer In this dialog I create a second modal dialog

    void RTMDialog::Percolate()
    {
    CMypercolate DOPREC(this);
    DOPREC.DoModal();
    }

    here too the this pointer is valid however when I get to this constructer pParent is null

    CMypercolate::CMypercolate(CWnd* pParent /*=NULL*/)
    : CDialog(IIDD_MYPERCOLATE, pParent)
    {

    L 1 Reply Last reply
    0
    • F ForNow

      I have a modeless dialog from which I display to two modal dialog boxes one after the other I would like to save all the information I get from the two in the modeless dialog So my plan was when creating the modal dialog box pass the Cwnd pointer using the this pointer Well the first one seems to work by this I mean make breakpoint

      abendialog = new RTMDialog(mylparam,this);

      at the creation of the object and then at the contructor

      RTMDialog::RTMDialog(LPARAM mylparam, CWnd* pParent)
      : CDialog(IDD_DIALOG9, pParent)

      at this pParent has valid pointer In this dialog I create a second modal dialog

      void RTMDialog::Percolate()
      {
      CMypercolate DOPREC(this);
      DOPREC.DoModal();
      }

      here too the this pointer is valid however when I get to this constructer pParent is null

      CMypercolate::CMypercolate(CWnd* pParent /*=NULL*/)
      : CDialog(IIDD_MYPERCOLATE, pParent)
      {

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      Hardly surprising the question you need to ask yourself as a learning exercise What is difference between instantiating an object using new vs. without AKA there is a difference between these two things abendialog = new RTMDialog(mylparam,this); CMypercolate DOPREC(this); The hint is where is the object put in the two different cases? Hmmm your into your mutitasking so what is wrong with this which is the same thing

      void SomeCreateCall (void){
      char[256] data;
      CreateThread(NULL, 0, SomeThreadFunction, (LPVOID)&data, 0, NULL);
      }

      The variable data above is obviously valid to pass so whats the problem and whats the fix?

      In vino veritas

      F 1 Reply Last reply
      0
      • L leon de boer

        Hardly surprising the question you need to ask yourself as a learning exercise What is difference between instantiating an object using new vs. without AKA there is a difference between these two things abendialog = new RTMDialog(mylparam,this); CMypercolate DOPREC(this); The hint is where is the object put in the two different cases? Hmmm your into your mutitasking so what is wrong with this which is the same thing

        void SomeCreateCall (void){
        char[256] data;
        CreateThread(NULL, 0, SomeThreadFunction, (LPVOID)&data, 0, NULL);
        }

        The variable data above is obviously valid to pass so whats the problem and whats the fix?

        In vino veritas

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        The stack data or local data disappears once the functions exists Thank so much

        L 1 Reply Last reply
        0
        • F ForNow

          The stack data or local data disappears once the functions exists Thank so much

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          Correct pretty sure same thing is going to happen with your code, I wouldn't hold the dialog on the stack on a modeless dialog. It's pretty dangerous to do, hold it as local data in the first dialog or on the heap same as you would on a multitask code :-)

          In vino veritas

          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