Example 3
Getting data back from a Device Driver
#include <winioctl.h> #include <iostream.h> #include "ioctls.h" // this has our IOCTL int main(int argc, char* argv[]) { HANDLE hDevice ; char sOutPut[512]; DWORD dwDummy; hdevice = CreateFile("\\\\.\\MyDriver", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hdevice == INVALID_HANDLE_VALUE) { cout << "Can't open Driver" << endl; return -1; } if (DeviceIoControl(hDevice, IOCTL_READ_FILE, NULL, 0, sOutPut, sizeof(sOutPut), &dwDummy, NULL)) { sOutPut[dwUnused] = 0; cout << sOutPut << endl; } else { cout << "Error " << GetLastError() << " in call to DeviceIoControl" << endl; } CloseHandle(hdevice); return 0; }