DeviceIoControl,将int传递给驱动程序

时间:2015-02-25 12:53:53

标签: c++ driver wdk kmdf

驱动:

PIO_STACK_LOCATION pIoStackLocation = IoGetCurrentIrpStackLocation(pIrp);
PVOID pBuf = pIrp->AssociatedIrp.SystemBuffer;

switch (pIoStackLocation->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_TEST:

    DbgPrint("IOCTL IOCTL_TEST.");
    DbgPrint("int received : %i", pBuf);

    break;
}

用户空间应用:

int test = 123;
int outputBuffer;

DeviceIoControl(hDevice, IOCTL_SET_PROCESS, &test, sizeof(test), &outputBuffer, sizeof(outputBuffer), &dwBytesRead, NULL);
std::cout << "Output reads as : " << outputBuffer << std::endl;

用户空间应用程序打印出通过输出缓冲区接收的正确值,但在调试视图中,打印出来的值似乎是垃圾(即:&#34; int收到:169642096&#34;)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

正如前一个用户所说,您正在打印变量的地址,而不是内容。

我强烈建议您查看以下驱动程序开发教程:

http://www.opferman.com/Tutorials/