【.Net】C#调用DLL接口

文章目录
  1. 1. 调用 Kernel32 中的函数

概述:C# 代码中调用 DLL 中的接口

如下所示:调用过程很简单。

调用 Kernel32 中的函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_BASIC_INFORMATION
{
public IntPtr BaseAddress;
public IntPtr AllocationBase;
public uint AllocationProtect;
public IntPtr RegionSize;
public uint State;
public uint Protect;
public uint Type;
}

[DllImport("kernel32.dll")]
public static extern int VirtualQuery(IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);