DeviceIoControl,将int传递给驱动程序

DeviceIoControl, passing an int to driver

本文关键字:驱动程序 int DeviceIoControl      更新时间:2023-10-16

驱动程序:

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;

用户空间应用程序打印出通过输出缓冲区返回的正确值,但在调试视图中,打印出的值似乎是垃圾(即:"int received:169642096")

我做错了什么?

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

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

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