0

I have a problem with using DeviceIOControl to put 128 byte buffer to my driver, i use this code:

int Initialize(unsigned char* public_signature, int size)
{
    int ret = DeviceIoControl( 
    DeviceFileHandle,
    2236440,
    public_signature,
    size,
    NULL,
    0,
    NULL,
    NULL);



    if(ret != 0)
        return 0;

    wprintf(L"Format message failed with 0x%x\n", GetLastError()); // always error 0x6!

    return 1;

}

I always get 0x6 error, what i'm doing wrong?

upd My handle creating function:

int CreateFileHandle()
{
    DeviceFileHandle = CreateFile( L"\Device\test",
    GENERIC_WRITE,
    GENERIC_READ | GENERIC_WRITE,
    NULL,
    OPEN_EXISTING,
    0,
    0);
    if(DeviceFileHandle)
        return 0;
    return 1;
}
Roman
  • 1,377
  • 2
  • 11
  • 12

1 Answers1

2

The error is in the 1st parameter of CreateFile. In your example, it would try to open a file, not a device. In addition, you didn't escape backslashes in the string. \t and similar are interpreted as special characters in C++.

The device name should be "\\\\.\\Device\\test".

Andriy
  • 8,486
  • 3
  • 27
  • 51