我创建了两个不同的Visual C#dll,它们使用了DeviceIOControl调用,我已将它们定义如下:
在第一个dll:
[DllImport("kernel32.dll", SetLastError = true)]
static extern BOOL DeviceIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
ref Internal_COMMAND lpInBuffer,
DWORD nInBufferSize,
ref ulong lpOutBuffer,
DWORD nOutBufferSize,
ref DWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped);
public struct Internal_COMMAND
{
public ulong Address;
public ulong Command;
};
在第二个dll中:
[DllImport("kernel32.dll", SetLastError = true)]
static extern BOOL DeviceIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
ref char[] lpInBuffer,
DWORD nInBufferSize,
ref char[] lpOutBuffer,
DWORD nOutBufferSize,
ref DWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped);
但现在我必须将它们作为同一类中的单个dll。所以我尝试使用下面的内容。
[DllImport("kernel32.dll", SetLastError = true)]
static extern BOOL DeviceIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
ref char[] lpInBuffer,
DWORD nInBufferSize,
ref char[] lpOutBuffer,
DWORD nOutBufferSize,
ref DWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped);
作为通用定义并通过将结构转换为字符数组来传递变量。但是驱动程序没有按预期工作
请指导我按照正确的程序进行操作
答案 0 :(得分:0)
方法重载就像@Hans Passant指出
一样这意味着我可以在单个.cs文件中使用这两个定义,并且方法重载生效,允许使用具有不同参数的相同函数