GetDelegateForFunctionPointer() across process boundaries?

::: {.Section1} [O Lazy Web, I Invoke Thee:]{style="font-size:10.0pt;font-family:Arial;color:navy"}

[ ]{style="font-size:10.0pt;font-family:Arial;color:navy"}

[I am trying to call a function in a DLL that I’ve injected into an arbitrary number of processes. ]{style="font-size:10.0pt;font-family:Arial;color:navy"}

[ ]{style="font-size:10.0pt;font-family:Arial;color:navy"}

[I need to call a function **on that instance** of the DLL running in the target process. So, I tried…]{style="font-size:10.0pt;font-family:Arial;color:navy"} [ ]{style="font-size:10.0pt;font-family:Arial;color:navy"}   [//hookedProcesses == List\ as you’d expect]{style="font-size:10.0pt;font-family:Arial;color:navy"} [//myDll == string initialized to path of my injected DLL, as you’d expect]{style="font-size:10.0pt;font-family:Arial;color:navy"} [//delegate void VoidDelegate() as you’d expect ]{style="font-size:10.0pt;font-family:Arial;color:navy"} [foreach(ProcessModule process in hookedProcesses)]{style="font-size:10.0pt;font-family:Arial;color:navy"} [{]{style="font-size:10.0pt;font-family:Arial;color:navy"} [   if(module.FileName == myDll) ]{style="font-size:10.0pt;font-family:Arial;color:navy"} [  { ]{style="font-size:10.0pt;font-family:Arial;color:navy"} [    IntPtr dllHandle = Interop.GetModuleHandle(filename); //Interop to Win32 GetModuleHandle()]{style="font-size:10.0pt;font-family:Arial;color:navy"} [    IntPtr funcPtr = Interop.GetProcAddress(dllHandle, “MyFunction”); //Interop to Win32 GetProcAddress()]{style="font-size:10.0pt;font-family:Arial;color:navy"} [    VoidDelegate func = (VoidDelegate) Marshall.GetDelegateForFunctionPointer(funcPtr, typeof(VoidDelegate));]{style="font-size:10.0pt;font-family:Arial;color:navy"} [            ]{style="font-size:10.0pt;font-family:Arial;color:navy"} [    // EVERYTHING WORKS TO THIS POINT. ]{style="font-size:10.0pt;font-family:Arial;color:navy"} [   func(); //]{style="font-size:10.0pt;font-family:Arial;color:navy"}

:::