问题
I'm using UnmanagedExports By RobertGiesecke
I want to export DllMain entrypoint.
Here what I've tried
[DllExport("DllMain", CallingConvention.StdCall)]
public static bool DllMain(IntPtr hModule, uint dwReason, byte[] lpReserved)
{
// I Write a text to file here
return true;
}
Then I call LoadLibrary but nothing happens. Any solution?
回答1:
Hooray, I found a way by using static constructor.
Just make class that contains exports static, and add static method.
public static class Class1
{
static Class1()
{
Console.WriteLine("DLL MAIN (Only DLL_PROCESS_ATTACH) :D");
}
[DllExport("AddFunc", CallingConvention.Cdecl)]
public static int AddFunc(int a, int b)
{
return a + b + 1;
}
}
When AddFunc called, Program first call Class1(Only one time) next call AddFunc
Anyway for DLL_PROCESS_DETACH ?
来源:https://stackoverflow.com/questions/39933033/c-sharp-implementing-dllmain-with-dllexport