Question

I want to send pipe handle to the other processes. To send the pointer, i converted it to the string.

   sprintf(handleToChar, "%p", handle);

so if value of handle is 0x00043c i get a memory with "00043c". I send it.

I receive it in the right form of "00043c".

I am unable to convert it back. I tried using sprintf again, but that is wrong as i realized later.

 sprintf((char*)handle, "%s", handleToChar); // <-- wrong

i thought atoi would do but there can be characters too in the string. so it failed again.

How can i do it ?

Was it helpful?

Solution

You simply can't. Addresses can't be shared between processes.

If you want to share a resource between two processes, you have to create a shared resource, or save/send other data so that the other process can create its own handle.

OTHER TIPS

Try boost interprocess, you can create shared memory

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top