C# Implementing DllMain with DllExport

旧街凉风 提交于 2020-01-05 05:27:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!