when I call this CallExport function, GetProcAdress(module, "Main") returns 0 and I don't know why. The LoadLibraryEx just before works and returns a valid IntPtr.
public class ProcessInteraction {
public static bool CallExport(Process process, string dll, string function)
{
IntPtr module = LoadLibraryEx(dll, IntPtr.Zero, 1);
if (module == IntPtr.Zero) return false;
IntPtr functionAddress = GetProcAddress(module, function);
if (functionAddress == IntPtr.Zero) return false;
functionAddress = GetModule(process, dll).BaseAddress + (int)functionAddress - (int)module;
IntPtr thread = CreateRemoteThread(process.Handle, IntPtr.Zero, IntPtr.Zero, functionAddress, IntPtr.Zero, 0, IntPtr.Zero);
if (thread == IntPtr.Zero) return false;
WaitForSingleObject(thread, 0xFFFFFFFF);
CloseHandle(thread);
return true;
}
}
In my Dll code I have :
internal class EntryPoint {
[DllExport("Main")]
internal static void Main() {
// some code ...
}
}
It seems like GetProcAdress(module, "Main") can't find the "Main" function inside my dll, even though there is one.