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.
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
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.
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.
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.
Bookmarks