get pointer address from text file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: get pointer address from text file

  1. #1
    Join Date
    Nov 2009
    Posts
    19

    get pointer address from text file

    i have a pointer address that is stored in a .txt file.
    how can i load the address from the txt to another pointer in my program?

    txt file contains something like:
    0x0012FF38

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: get pointer address from text file

    You can simply load it as a textfile and convert it with sscanf or something, but the bigger question here is ... WHY are you storing a pointer address in a textfile ? Pointer are relative to the space your program is running in and therefor storing it on disk is totally useless.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: get pointer address from text file

    Read it as text, then use strtol (or wcstol for UNICODE) with the base = 16.
    BTW, what are you going to do with such a "pointer address"?
    Victor Nijegorodov

  4. #4
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: get pointer address from text file

    Quote Originally Posted by coopers View Post
    i have a pointer address that is stored in a .txt file.
    how can i load the address from the txt to another pointer in my program?

    txt file contains something like:
    0x0012FF38
    Don't know, what's the use of it (are you trying to communicate a shared memory address?), but you should probably read it into a long and then cast it to the required pointer type:
    Code:
      std::ifstream f("address.txt");
      unsigned long i;
      if (f >> std::hex >> i) {
        void * p = reinterpret_cast<void *>(i);
        std::cout << "The address is " << p << std::endl;
      }
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: get pointer address from text file

    Wait, doesn't matter how he can read it. As Skizmo said, it doesn't make any sense. Pointers are not to be store and loaded lately. You store the objects they point to.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Nov 2009
    Posts
    19

    Re: get pointer address from text file

    i have to make two different application, A and B.

    A has to verify if B is running and B has to verify if A is running.

    A and B are completely different.

    so i thought that if I make volatile variables in both apps, and from time to time the app has to change the other app the volatile.

    if volatile is not changed, then one is not running.

    and the change is being made through a pointer to volatile.

    Hope that you have another solution :d

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: get pointer address from text file

    Hope that you have another solution :d
    Google for 'shared memory'

  8. #8
    Join Date
    Apr 1999
    Posts
    27,424

    Re: get pointer address from text file

    Quote Originally Posted by coopers View Post
    i have to make two different application, A and B.

    A has to verify if B is running and B has to verify if A is running.

    A and B are completely different.
    You use the OS facilities to determine if a process is running or not, not faulty C++ coding. Do you think that commercial apps that need to know if a service, process, etc. is running use your method?

    How does an install program know that a certain app is running, and then asks you to close the app before proceeding the installation? I doubt it has anything to do with volatile variables, since those apps may not even have been coded using C or C++.

    Pointers are not permanent. They only exist during the run of an application, and only that application knows about its own pointers. Storing an address is meaningless.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,826

    Re: get pointer address from text file

    The good/safe way out is that both applications make a named mutex to indicate they are running. This same mutex can also be used to verify that no 2 copies of either peograms are running (if you need to have that feature, you'll need a semaphore instead).

    The applications also periodically verify that the named mutex of the other application is available. If not, the other app is still running, if yes, then the other program has stopped running.

  10. #10
    Join Date
    Nov 2009
    Posts
    19

    Re: get pointer address from text file

    applications will be some windows services.They aren't visible in Task Manager.

  11. #11
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: get pointer address from text file

    Quote Originally Posted by coopers View Post
    applications will be some windows services.They aren't visible in Task Manager.
    but you can query the list of services to see what is running and what isn't.

  12. #12
    Join Date
    Apr 1999
    Posts
    27,424

    Re: get pointer address from text file

    Quote Originally Posted by coopers View Post
    applications will be some windows services.They aren't visible in Task Manager.
    And there are third-party "Task Manager" clones that do show all running processes. Every running process can be determined by calling the right OS functions.

    Task Manager is just another application -- I don't know why you're using that to determine what you can or can't do.

    Regards,

    Paul McKenzie

  13. #13
    Join Date
    Nov 2009
    Posts
    19

    Re: get pointer address from text file

    i am going to use Mutex Objects.

    i was looking for interprocess communication.

  14. #14
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: get pointer address from text file

    Quote Originally Posted by coopers View Post
    i am going to use Mutex Objects.

    i was looking for interprocess communication.
    Good call. Here is an FAQ that shows how to use a mutex to see if an instance of an application already exists: http://www.codeguru.com/forum/showthread.php?t=312467.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center