Thread: Changing a var by another app

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246

    Changing a var by another app

    I want to write a program that should change another program's var (when both are executing), Is it possible?
    Last edited by siavoshkc; 01-27-2006 at 11:49 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    It's POSSIBLE, but it's not easy. You'd need an OS-level app to do it, since accessing memory outside an app's allocated space typically results in a segfault - or a General Protection Fault in Win32 land.

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Yes, but keep in mind that I am writing both the apps myself.
    For example a non-practical way is to make the program read from a file and tell the other to write the new value to it. Or a better way is using windows registry. But as you concluded I want to change the var in mem.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So make both "programs" into threads within the same program then.
    Then they can play with each other's memory as much as they like, since threads occupy the same address space.

    But then you've got to then consider all the associated problems of exclusion, synchronisation and a whole host of other problems which don't affect sequential programs.

    Or if it really is
    - program 1 reads file
    - program 2 processes file
    Then go with the ultra easy always works answer of two sequential function calls in the same program.

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    >>So make both "programs" into threads within the same program then.

    How can I do that? I want two seperate exe files.
    And give a simple function to create a value in win reg.
    Last edited by siavoshkc; 01-28-2006 at 05:08 AM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A nice portable way for two programs to share information is called a file.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    There are various methods of communicating between programs. Look up "interprocess communication".

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    I should notice that I prefer not to use windows functions.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Or a better way is using windows registry.
    > I should notice that I prefer not to use windows functions.
    Ohhhhhkkkkaaaayyyyyyy - now we know, thanks for the heads up.

  10. #10
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    > I should notice that I prefer not to use windows functions.

    Your original post indicated you want one program to change a variable's value in another program. The only way you can avoid win32 api functions is if you use the file system to exchange data. All other methods (sockets, threads, pipes, COM, registry, etc) will use win32.

  11. #11
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    You could thread them, then have 2 shortcuts to the program, and comandline options to start one or the other or both.

  12. #12
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Is it possible for a program to share memory with other apps and tell windows that "my memory is for all!"? Yes it needs a windows function but it doesn't use it's capabilities it just say don't protect my memory.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  13. #13
    Distributed Programming beyonddc's Avatar
    Join Date
    Dec 2001
    Location
    Mass
    Posts
    31
    Yes, you can use shared memory on Windows, I never tried it on Windows before though. I only tried it on Solaris using Adaptive Communication Framework.

    You can try search on MSDN Site on how to use shared memory.

    I searched msdn site, and found this article that might be able to help you out a bit.

    But it sounds like people suggestion is good also by reading from file.
    -dc

  14. #14
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    >>But it sounds like people suggestion is good also by reading from file.
    It is my suggestion:-) (third post) .
    Thank you so much I'll take a look at it.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  15. #15
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    MS-Windows does not support shared memory like *nix. Probably the closest thing would the the clipboard. you can post data to the clipboard and other applications can read it. MS-Windows also has memory mapped files -- I have never used them but I know they are another way to share information between applications.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help assignment
    By 6kaine9 in forum C Programming
    Replies: 26
    Last Post: 10-19-2008, 08:51 PM
  2. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  3. server question
    By xddxogm3 in forum Tech Board
    Replies: 24
    Last Post: 01-21-2004, 01:12 AM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM
  5. Vigenere Decipher/Encipher
    By Xander in forum C++ Programming
    Replies: 5
    Last Post: 02-15-2002, 09:24 AM