Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>An alternative means</strong><br/></p> <p>&emsp;&emsp;While I'm not quite sure if this falls under "shared memory" <i>(since you can also use this method to send data to DLLs loaded in separate processes, as well)</i>... You could allocate some memory at a specific address using <code>VirtualAllocEx</code>, pass in a struct containing all the data the DLL will need using <code>WriteProcessMemory</code>, then lock it with <code>VirtualLock</code> before loading the DLL.</p> <p>Then in the DLL's entry point function, I would use <code>VirtualUnlock</code>, grab that data using <code>ReadProcessMemory</code>, then <code>VirtualFree</code> to clean up resources.<br/></p> <p>Although a bit choppy, this is especially useful if you have more than just a simple string to pass on.<br/> Note that you must have read/write access in the target process for this to work.<br/>&nbsp;</p> <p><strong>Example</strong> (pseudo-code)<br/></p> <pre><code>// YourApp.cpp struct DataToSend { int myInt; char myStr[320]; }; DataToSend m_data = { 1337, "This is a test string...\0" }; // ... PVOID remoteData = VirtualAllocEx( hTargetProcess, NULL, sizeof(m_data), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE ); WriteProcessMemory( hTargetProcess, remoteData, &amp;m_data, sizeof(m_data), NULL ); VirtualLock( remoteData, sizeof(m_data) ); // Save the address (DWORD) of remoteData to the registry, to a local file, or using setenv as suggested in other answers here </code></pre> <p>&nbsp;</p> <pre><code>// YourDll.cpp BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { DataToSend m_data = {0}; PVOID localData = /* address used in YourApp */ NULL; //... VirtualUnlock( localData, sizeof(m_data) ); ReadProcessMemory( hProcess, localData, &amp;m_data, sizeof(m_data), NULL ); VirtualFree( localData, 0, MEM_RELEASE ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload