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. Other Discussions
  3. Article Writing
  4. sharing a pointer between the applications

sharing a pointer between the applications

Scheduled Pinned Locked Moved Article Writing
questionc++
4 Posts 4 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.
  • Y Offline
    Y Offline
    yamini
    wrote on last edited by
    #1

    I have created two exes(MFC).I am posting a pointer to the structure thro' PostThreadMessage from one exe (struct message { int messageid; CString messagedescription; }; the members are initialized ) The other exe should receive the pointer posted by the thread from other exe & it should display the member values.But, in my case the structure is getting posted successfully !But, I am getting some junk values in the receiving exe. How can I get the desired values, then ? Y.Yamini Devi

    M A 2 Replies Last reply
    0
    • Y yamini

      I have created two exes(MFC).I am posting a pointer to the structure thro' PostThreadMessage from one exe (struct message { int messageid; CString messagedescription; }; the members are initialized ) The other exe should receive the pointer posted by the thread from other exe & it should display the member values.But, in my case the structure is getting posted successfully !But, I am getting some junk values in the receiving exe. How can I get the desired values, then ? Y.Yamini Devi

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      You can't pass data between different programs like that. Each program has its own address space, and pointers in one app don't make sense in another app. Either switch to WM_COPYDATA or use memory-mapped files. --Mike-- http://home.inreach.com/mdunn/ This must be Thursday. I never could get the hang of Thursdays...

      R 1 Reply Last reply
      0
      • M Michael Dunn

        You can't pass data between different programs like that. Each program has its own address space, and pointers in one app don't make sense in another app. Either switch to WM_COPYDATA or use memory-mapped files. --Mike-- http://home.inreach.com/mdunn/ This must be Thursday. I never could get the hang of Thursdays...

        R Offline
        R Offline
        RockNix
        wrote on last edited by
        #3

        There is more way to share data between 2 or more apps. Write a simple dll and set the variable you want to share as followed: #pragma data_seg("shared") int x=0; #pragma data_seg() #pragma comment(linker,"/SECTION:shared,RWS") if you add this to a dll the variable x will be readable from all apps using this dll. if more than one process will write to x you should not forget synchronisation. BEWARE: Shared data must be init !!! This works not with dynamic variables ! Hope that helps - Mario P.S.: Sharing pointers via PostMessage has only worked under win 3.x ! ----------------------- www.klangwerker.de mario@klangwerker.de -----------------------

        1 Reply Last reply
        0
        • Y yamini

          I have created two exes(MFC).I am posting a pointer to the structure thro' PostThreadMessage from one exe (struct message { int messageid; CString messagedescription; }; the members are initialized ) The other exe should receive the pointer posted by the thread from other exe & it should display the member values.But, in my case the structure is getting posted successfully !But, I am getting some junk values in the receiving exe. How can I get the desired values, then ? Y.Yamini Devi

          A Offline
          A Offline
          Ancient Dragon
          wrote on last edited by
          #4

          You cannot pass pointers from one process to another. Each process has its own address space, so a pointer in process A points to process A's address space. Process B cannot access any data in process A. The simpliest way to resolve this is to write the data to a file that can be read by process B. Another way may be for process A to put the data into the clipboard and process B to extract it. There are other ways but much more complicated and involves advanced COM+ programming.;)

          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