当我调用此CallExport函数时,GetProcAdress(模块," Main")返回0并且我不知道原因。工作之前的LoadLibraryEx并返回一个有效的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;
}
}
在我的Dll代码中,我有:
internal class EntryPoint {
[DllExport("Main")]
internal static void Main() {
// some code ...
}
}
似乎GetProcAdress(模块," Main")无法找到" Main"在我的dll中运行,即使有一个。