-
November 5th, 2009, 08:37 AM
#1
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
-
November 5th, 2009, 08:49 AM
#2
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.
-
November 5th, 2009, 08:51 AM
#3
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
-
November 5th, 2009, 09:00 AM
#4
Re: get pointer address from text file
Originally Posted by coopers
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.
-
November 5th, 2009, 09:06 AM
#5
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.
-
November 5th, 2009, 10:09 AM
#6
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
-
November 5th, 2009, 10:16 AM
#7
Re: get pointer address from text file
Hope that you have another solution
Google for 'shared memory'
-
November 5th, 2009, 10:20 AM
#8
Re: get pointer address from text file
Originally Posted by coopers
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
-
November 5th, 2009, 10:49 AM
#9
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.
-
November 6th, 2009, 07:32 AM
#10
Re: get pointer address from text file
applications will be some windows services.They aren't visible in Task Manager.
-
November 6th, 2009, 09:11 AM
#11
Re: get pointer address from text file
Originally Posted by coopers
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.
-
November 6th, 2009, 10:34 AM
#12
Re: get pointer address from text file
Originally Posted by coopers
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
-
November 6th, 2009, 03:01 PM
#13
Re: get pointer address from text file
i am going to use Mutex Objects.
i was looking for interprocess communication.
-
November 6th, 2009, 03:20 PM
#14
Re: get pointer address from text file
Originally Posted by coopers
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|