2012-10-09 48 views
0

我有使用DeviceIOControl把128字节的缓冲区,以我的驱动程序有问题,我用这个代码:的DeviceIoControl与输入的无符号字符缓冲区C++

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; 

} 

我总是为0x6的错误,我在做什么错?

UPD 我把手创建功能:

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

回答

2

的错误是在CreateFile的第一个参数。在你的例子中,它会尝试打开一个文件,而不是设备。另外,你没有在字符串中逃避反斜杠。在C++中将\t和类似语句解释为特殊字符。设备名称应为"\\\\.\\Device\\test"