1

我正在使用RobertGiesecke的UnmanagedExports

我想导出DllMain入口点。

这是我尝试过的

[DllExport("DllMain", CallingConvention.StdCall)]
public static bool DllMain(IntPtr hModule, uint dwReason, byte[] lpReserved)
{ 
  // I Write a text to file here
  return true; 
}

然后我调用LoadLibrary但没有任何反应。有什么解决办法吗?

4

1 回答 1

0

万岁,我找到了一种使用静态构造函数的方法。

只需将包含导出的类设为静态,并添加静态方法。

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;
    }
}

当调用 AddFunc 时,程序首先调用 Class1(仅一次)下一次调用 AddFunc

无论如何 DLL_PROCESS_DETACH ?

于 2016-10-19T16:53:25.660 回答