O Lazy Web, I Invoke Thee:
I am trying to call a function in a DLL that I’ve injected into an arbitrary number of processes.
I need to call a function on that instance of the DLL running in the target process. So, I tried…
//hookedProcesses == List<ProcessModule> as you’d expect
//myDll == string initialized to path of my injected DLL, as you’d expect
//delegate void VoidDelegate() as you’d expect
foreach(ProcessModule process in hookedProcesses)
if(module.FileName == myDll)
IntPtr dllHandle = Interop.GetModuleHandle(filename); //Interop to Win32 GetModuleHandle()
IntPtr funcPtr = Interop.GetProcAddress(dllHandle, “MyFunction”); //Interop to Win32 GetProcAddress()
VoidDelegate func = (VoidDelegate) Marshall.GetDelegateForFunctionPointer(funcPtr, typeof(VoidDelegate));
// EVERYTHING WORKS TO THIS POINT.