代码:
dynamic user32 = new DynamicDllImport("user32.dll", callingConvention : CallingConvention.Winapi);
user32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0); 有返回参数:
dynamic asmproject = new DynamicDllImport("asmproject.dll");
int value = asmproject.add<int>(3, 4);
Console.WriteLine(value); 有out,ref参数
dynamic sdl = new DynamicDllImport("SDL.dll", CharSet.Ansi);
Sdl.SDL_Rect rect = new Sdl.SDL_Rect(
0,
0,
(short)width,
(short)height);
int result = sdl.SDL_FillRect<int>(rgbSurfacePtr, ref rect, 0);
Sdl.SDL_Event evt;
while (sdl.SDL_WaitEvent(out evt) != 0)
{
if (evt.type == Sdl.SDL_QUIT)
{
break;
}
}
原文地址
本文演示了如何使用C#动态调用不同DLL文件中的函数,包括无返回值、有返回值、带参数、带out参数和ref参数的函数。
6162

被折叠的 条评论
为什么被折叠?



