- hDev = CreateFile(NDISUIO_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
- if(hDev == INVALID_HANDLE_VALUE) {
- CString s;
- s.Format(_T("CreateFile失败::%d"),GetLastError());
- AfxMessageBox(s);
- return;
- }
-
- //IOCTL_NDISUIO_OPEN_WRITE_DEVICE
- if(!DeviceIoControl(hDev, IOCTL_NDISUIO_OPEN_DEVICE, szEthName, sizeof(szEthName) , NULL, 0, NULL, NULL))
- {
- CString s;
- s.Format(_T("IOCTL_NDISUIO_OPEN_DEVICE失败::%d,%d"),GetLastError(),sizeof(szEthName));
- AfxMessageBox(s);
- return;
- }
-
- EthHeader.EthType[0] = 0x68;
- EthHeader.EthType[1] = 0x06;
- if(!DeviceIoControl(hDev, IOCTL_NDISUIO_SET_ETHER_TYPE,(USHORT*)EthHeader.EthType , sizeof(USHORT), NULL, 0, NULL, NULL))
- {
- CString s;
- s.Format(_T("IOCTL_NDISUIO_SET_ETHER_TYPE失败::%d"),GetLastError());
- AfxMessageBox(s);
- return;
- }
我的问题是CREATEFILE OK。。然后在IOCTL_NDISUIO_OPEN_DEVICE的时候出错,错误ID 31:连到系统上的设备没有发挥作用
然后我试试改改,把sizeof(szEthName)改掉,改成1024. OPEN_DEVICE又OK了。
但是这里,在说明文档里说了:
lpInBuffer
[in] Points to the adapter name that will be associated with the file handle.
nInBufferSize
[in] Size, in bytes, of the buffer pointed to by lpInBuffer.
This value should be the size of the adapter name only. The NULL character should be disregarded.
我这里没有这样做,反而不报错了。
然后到IOCTL_NDISUIO_SET_ETHER_TYPE,直接出现错误50:不支持请求。
我不知道如何去解决它~