tags:

views:

94

answers:

3

Hi all,

I have a structure and a member of it is char* * (2d pointer). I allocate space from EXE1 and call EXE2 with the data. I use memcpy to get all data on EXE2. The memory address on both EXE is the same (lets say 0x013740b0), though the data of char** on EXE2 are not present. How can I retrieve the data on EXE2?

Thanks in advance, SunScreen

+6  A: 

You can not share pointers like that as each exe is having its own virtual address space and whatever address you are seeing is not a physical address, it is virtual address. This virtual address will be translated into different physical addresses in different exes. You can use shared memory to share the data between different processes.

Naveen
A: 

I think you can not refer to anoher memory address in another executable directly, if you want this behaviour you have to make shared dll and put your structure in a shared place

Ahmed Said
that won't work either as in an application each DLL has also it's own address space.
jdehaan
yes, but you can declare global section!!!
Ahmed Said
That's a quite dirty hack. Unlike proper shared memory, DLL shared data sections bypass the NT security model.
MSalters
+1  A: 

Naveen is correct.

You can try something like this:

  HGLOBAL hglbBuf = GlobalAlloc(GMEM_MOVEABLE, buffer_size);
  if (  hglbBuf == NULL  ) {
    // ...
    return;
  }

  /* do something with the buffer */
  void* buf = (void*)GlobalLock(hglbBuf);
  // ...
  GlobalUnlock(hglbBuf);
Nick D
No - GLobalAlloc is Global to the process (The difference with LocalAlloc became theoretical after the Win16->Win32 changeover). EXE2 has its own, distinct "Global" addresses.--- Also, you don't need GlobalLock in Win32
MSalters
@MSalters, I don't think so. For example, MSDN samples use GlobalAlloc to pass clipboard data.
Nick D