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
Printable View
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
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.
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"? :confused:
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;
}
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.
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
Google for 'shared memory'Quote:
Hope that you have another solution :d
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
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.
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
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.