0

I have created two different Visual C# dll's that make use of DeviceIOControl calls and I have defined them as below:

In first 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;
};

In second 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);

But now I have to make them as a single dll within the same class. So I tried to use the below.

[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);

as common definition and passed the variables by converting structure to character array. But the driver does not work as expected

Please guide me with the correct procedure to follow

cramopy
  • 3,459
  • 6
  • 28
  • 42
hazzelnuttie
  • 1,403
  • 1
  • 12
  • 22
  • 1
    What on Earth was the point of not posting the code that matters?? Throw that code away, it is broken and completely unnecessary. The C# language supports method overloads, works just as well when they have an attribute. – Hans Passant Mar 28 '16 at 10:07
  • @HansPassant Hi... It works as you said I used method overload.... Sorry being so dumb – hazzelnuttie Mar 28 '16 at 10:45

1 Answers1

0

Method overload just worked just as @Hans Passant pointed out

This means I can use both definitions in a single .cs file and method overload takes effect, allowing to use the same function with different parameters

hazzelnuttie
  • 1,403
  • 1
  • 12
  • 22