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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. pass complex data type from CMyapp to CMyDoc (std MFC stuf)

pass complex data type from CMyapp to CMyDoc (std MFC stuf)

Scheduled Pinned Locked Moved C / C++ / MFC
c++
3 Posts 3 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.
  • U Offline
    U Offline
    User 530985
    wrote on last edited by
    #1

    We need to pass a struct from CMyapp to CMyDoc. Is it possible to do this, and how painfull will it be. Thanks in advance -Fred

    RaviBeeR A 2 Replies Last reply
    0
    • U User 530985

      We need to pass a struct from CMyapp to CMyDoc. Is it possible to do this, and how painfull will it be. Thanks in advance -Fred

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      The app could (selectively) allow the doc could access it by exposing a getAtComplexData() API. Your doc would do:

      CMyApp* pMyApp = (CMyApp *) AfxGetApp();
      ASSERT (pMyApp != NULL);
      ComplexData* pComplexData = pMyApp->getAtComplexData (this);
      if (pComplexData != NULL) {
      ...
      }

      /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

      1 Reply Last reply
      0
      • U User 530985

        We need to pass a struct from CMyapp to CMyDoc. Is it possible to do this, and how painfull will it be. Thanks in advance -Fred

        A Offline
        A Offline
        Antti Keskinen
        wrote on last edited by
        #3

        You have a few options available. As the structure exists in the application class (CMyApp), you can create a member function that returns the address of this structure. Now, if this method is called from inside CMyDoc, the document has the address of the structure, and can operate on it freely, providing that both objects reside on the same thread. If they do not, things get more complicated. Alternatively, taking an advanced step from the section above, you can create a structure into CMyDoc as well, then get a pointer from CMyApp and use memcpy to copy the structure data from CMyApp to CMyDoc. Now, CMyDoc contains a copy of the structure. The previous posted created an example piece to show you how to access the application object at run-time. Use this method to call the function that returns the structure address. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

        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