我正在尝试从用 C 编写的第三方 DLL 执行一些方法(在这种特殊情况下,rdOnAllDone),并查看头文件,我发现了这一点:
#ifndef TDECLSDONE
#ifdef STDCALL
#define CCON __stdcall
#else
#define CCON __cdecl
#endif
#define TDECLSDONE
#endif
#define DLLIMP __declspec (dllimport)
DLLIMP int CCON rdOnAllDone (void(CCON *)(int));
Run Code Online (Sandbox Code Playgroud)
在寻找调用此方法的方法之后,我做了这个:
[DllImport("sb6lib.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int rdOnAllDone(Delegate d);
public delegate void rdOnAllDoneCallbackDelegate();
private static void rdOnAllDoneCallback()
{
Console.WriteLine("rdOnAllDoneCallback invoked");
}
Run Code Online (Sandbox Code Playgroud)
该方法被正确调用,只是我无法获取 int 参数。所以我尝试像这样添加输入参数 int
[DllImport("sb6lib.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int rdOnAllDone(Delegate d);
public delegate void rdOnAllDoneCallbackDelegate(int number);
private static void rdOnAllDoneCallback(int number)
{
Console.WriteLine("rdOnAllDoneCallback invoked …Run Code Online (Sandbox Code Playgroud)