CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old January 15th, 2004, 02:17 PM
    guiemjulia guiemjulia is offline
    Member
     
    Join Date: Oct 2003
    Posts: 34
    guiemjulia is an unknown quantity at this point (<10)
    Memory problem in C

    Hi:

    I'm trying to do this:

    -A C program write the memory pointer to one of its structures in a file (ex: 00278F92). And after that, he waits in execution.

    -Another C Program begins its execution, open the file, catch 00278F92, and use it to point the structure (which is defined too in this second program of course). Then it begin to search in this structure, but it fails. At one moment i see that he's pointing to FFFFFFFF.

    If I write exactly the same code in the first program, something like this

    newstruct=0x00278F92;
    search(newstruct);

    It works fine! So I think this is a problem with shared memory or similar, the first program don't let the second to see "its" memory.

    Anybody knows how to work like this? What to doing?

    Thanks. A lot of thanks!
    Reply With Quote
      #2    
    Old January 15th, 2004, 04:26 PM
    Yves M's Avatar
    Yves M Yves M is offline
    Moderator
    Power Poster
     
    Join Date: Aug 2002
    Location: Madrid
    Posts: 4,560
    Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)
    This depends on your operating system. Most OSes these days give each process a virtual memory layout, which means that program a) can think its data is at 0x00278F92 and program b) thinks its data is at 0x00278F92, but yet these two adresses physically map to different memory.
    __________________
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.
    Reply With Quote
      #3    
    Old January 15th, 2004, 05:47 PM
    guiemjulia guiemjulia is offline
    Member
     
    Join Date: Oct 2003
    Posts: 34
    guiemjulia is an unknown quantity at this point (<10)
    and any idea about what to do?
    Reply With Quote
      #4    
    Old January 15th, 2004, 06:14 PM
    Mick's Avatar
    Mick Mick is offline
    Banned
     
    Join Date: Sep 2002
    Location: Maryland - Fear The Turtle!
    Posts: 7,537
    Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)
    well it depends on what you are attempting to do...just use a filemapping (CreateFileMapping(...) etc) if you want to transfer data back and forth via an IPC, otherwise use OpenProcess(...) and ReadProcessMemory(...)
    Reply With Quote
      #5    
    Old January 16th, 2004, 06:20 AM
    Yves M's Avatar
    Yves M Yves M is offline
    Moderator
    Power Poster
     
    Join Date: Aug 2002
    Location: Madrid
    Posts: 4,560
    Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)Yves M has much to be proud of (1500+)
    Quote:
    Originally posted by guiemjulia
    and any idea about what to do?
    Tell us which OS you are using and we may be able to help
    __________________
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.
    Reply With Quote
      #6    
    Old January 16th, 2004, 09:40 PM
    guiemjulia guiemjulia is offline
    Member
     
    Join Date: Oct 2003
    Posts: 34
    guiemjulia is an unknown quantity at this point (<10)
    XP, but i want to make it work at 2000 server.

    I'll look at the fuctions Micks say me.
    Reply With Quote
      #7    
    Old January 17th, 2004, 11:34 AM
    Sam Hobbs Sam Hobbs is offline
    Elite Member
    Power Poster
     
    Join Date: May 1999
    Location: Southern California
    Posts: 12,261
    Sam Hobbs has a spectacular aura about (125+)Sam Hobbs has a spectacular aura about (125+)
    My Processes and Address Spaces might help you to understand about memory.

    There are many Interprocess Communications (IPC) capabilities, and Mick mentioned a couple. (Actually I think that filemapping is the only IPC capability that Mick mentioned; I think that ReadProcessMemory is not normally considered an IPC solution.) The best solution depends on your requirements; the easiest is the WM_COPYDATA message.
    __________________
    "Signature":
    My web site is Simple Samples.
    Reply With Quote
      #8    
    Old January 17th, 2004, 08:41 PM
    Mick's Avatar
    Mick Mick is offline
    Banned
     
    Join Date: Sep 2002
    Location: Maryland - Fear The Turtle!
    Posts: 7,537
    Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)
    Quote:
    Originally posted by Sam Hobbs
    My Processes and Address Spaces might help you to understand about memory.

    There are many Interprocess Communications (IPC) capabilities, and Mick mentioned a couple. (Actually I think that filemapping is the only IPC capability that Mick mentioned; I think that ReadProcessMemory is not normally considered an IPC solution.) The best solution depends on your requirements; the easiest is the WM_COPYDATA message.
    because a filemapping is the most effiecent form of IPC.
    Reply With Quote
      #9    
    Old January 17th, 2004, 10:17 PM
    Sam Hobbs Sam Hobbs is offline
    Elite Member
    Power Poster
     
    Join Date: May 1999
    Location: Southern California
    Posts: 12,261
    Sam Hobbs has a spectacular aura about (125+)Sam Hobbs has a spectacular aura about (125+)
    The WM_COPYDATA message uses filemapping. The WM_COPYDATA message is definitely the most efficient for us (the programmer). So it depends on requirements, but an individual WM_COPYDATA message seems to me to be as efficient for Windows as if we were to code the filemapping ourselves and the WM_COPYDATA message would be immensely more efficient for us to program.
    __________________
    "Signature":
    My web site is Simple Samples.
    Reply With Quote
      #10    
    Old January 17th, 2004, 10:40 PM
    Mick's Avatar
    Mick Mick is offline
    Banned
     
    Join Date: Sep 2002
    Location: Maryland - Fear The Turtle!
    Posts: 7,537
    Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)
    Quote:
    Originally posted by Sam Hobbs
    The WM_COPYDATA message uses filemapping. The WM_COPYDATA message is definitely the most efficient for us (the programmer). So it depends on requirements, but an individual WM_COPYDATA message seems to me to be as efficient for Windows as if we were to code the filemapping ourselves and the WM_COPYDATA message would be immensely more efficient for us to program.
    there are alot of things that use a filemapping, but it is more effiecnet to cut out the middle man and associated calls with the middle man, and the processing overhead.
    Reply With Quote
      #11    
    Old January 17th, 2004, 10:58 PM
    Mick's Avatar
    Mick Mick is offline
    Banned
     
    Join Date: Sep 2002
    Location: Maryland - Fear The Turtle!
    Posts: 7,537
    Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)
    Quote:
    Originally posted by Sam Hobbs
    I think that ReadProcessMemory is not normally considered an IPC solution
    IPC is any process via software by which data is exchanged without human intervention.

    WriteProcessMemory(...)
    Signal write sync object (Mutex)
    other proc process data, signal read sync object.
    ReadProcessMemory(...)

    rinse and repeat

    I-P-C
    Reply With Quote
      #12    
    Old January 17th, 2004, 10:59 PM
    Sam Hobbs Sam Hobbs is offline
    Elite Member
    Power Poster
     
    Join Date: May 1999
    Location: Southern California
    Posts: 12,261
    Sam Hobbs has a spectacular aura about (125+)Sam Hobbs has a spectacular aura about (125+)
    Sometimes the savings in machine time do not justify the cost of people time. It depends on the situation and the programmer. Are you saying that the WM_COPYDATA message is never practical?
    __________________
    "Signature":
    My web site is Simple Samples.
    Reply With Quote
      #13    
    Old January 17th, 2004, 11:10 PM
    Mick's Avatar
    Mick Mick is offline
    Banned
     
    Join Date: Sep 2002
    Location: Maryland - Fear The Turtle!
    Posts: 7,537
    Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)
    Quote:
    Originally posted by Sam Hobbs
    Are you saying that the WM_COPYDATA message is never practical?
    of course not.
    Reply With Quote
      #14    
    Old January 17th, 2004, 11:20 PM
    Sam Hobbs Sam Hobbs is offline
    Elite Member
    Power Poster
     
    Join Date: May 1999
    Location: Southern California
    Posts: 12,261
    Sam Hobbs has a spectacular aura about (125+)Sam Hobbs has a spectacular aura about (125+)
    Quote:
    Originally posted by Mick
    IPC is any process via software by which data is exchanged without human intervention.
    Are you denying that ReadProcessMemory is a Debugging and Error Handling function? I don't know if ReadProcessMemory has more restrictive security requirements, but if it does, then that should be made clear when it is suggested as a solution.

    My definition of "normally considered an IPC solution" is something in the Interprocess Communications section of the Platform SDK. If you want to use a different definition of IPC, then you can, as long as it is clear that it differs from the Platform SDK definition.
    __________________
    "Signature":
    My web site is Simple Samples.
    Reply With Quote
      #15    
    Old January 17th, 2004, 11:28 PM
    Mick's Avatar
    Mick Mick is offline
    Banned
     
    Join Date: Sep 2002
    Location: Maryland - Fear The Turtle!
    Posts: 7,537
    Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)Mick is a splendid one to behold (750+)
    Quote:
    Originally posted by Sam Hobbs
    Are you denying that ReadProcessMemory is a Debugging and Error Handling function? I don't know if ReadProcessMemory has more restrictive security requirements, but if it does, then that should be made clear when it is suggested as a solution.

    My definition of "normally considered an IPC solution" is something in the Interprocess Communications section of the Platform SDK. If you want to use a different definition of IPC, then you can, as long as it is clear that it differs from the Platform SDK definition.
    sam, get off the tin foil hat details, the definintion of IPC is just what I stated. Microsofts definition of it's IPC api's is just that.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 09:22 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009