|
-
- LPCWSTR strDrvName=L"";
- strDrvName=TEXT("NDS0:");
- HANDLE hHandle;
- hHandle = CreateFile(strDrvName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
- INVALID_HANDLE_VALUE
- );
- if( hHandle == INVALID_HANDLE_VALUE )
- {
- AfxMessageBox(_T("createfile error"));
- return;
- }
- DWORD dwReturnedBytes;
- DWORD recvData[1024];
- DeviceIoControl(
- hHandle,
- IOCTL_NDIS_GET_ADAPTER_NAMES,
- NULL,
- 0,
- &recvData,
- 1024,
- &dwReturnedBytes,
- NULL);
- ::CloseHandle(hHandle);
- hHandle = CreateFile(_T("UIO1:"),
- GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- CREATE_NEW,
- FILE_ATTRIBUTE_NORMAL,
- INVALID_HANDLE_VALUE
- );
- if( hHandle == INVALID_HANDLE_VALUE )
- {
- AfxMessageBox(_T("createfile error"));
- return;
- }
- ////Query Binding
- dwReturnedBytes = 0;
- char buff[1024];
- PNDISUIO_QUERY_BINDING recvBuffer = (PNDISUIO_QUERY_BINDING)buff;
- DeviceIoControl( hHandle,
- IOCTL_NDISUIO_QUERY_BINDING,
- recvBuffer,
- sizeof(NDISUIO_QUERY_BINDING),
- NULL,
- 1024,
- &dwReturnedBytes,
- NULL
- );
- USHORT pDevName[1024];
- memset(pDevName, 0, 1024);
- memcpy(pDevName,&buff[recvBuffer->DeviceNameOffset],recvBuffer->DeviceNameOffset);
- CString s;
- s.Format(_T("%s"),pDevName);
- AfxMessageBox(s);
- ////Open Device
- dwReturnedBytes = 0;
- DeviceIoControl( hHandle,
- IOCTL_NDISUIO_OPEN_WRITE_DEVICE,
- pDevName,
- wcslen(pDevName)*sizeof(TCHAR),
- NULL,
- 0,
- &dwReturnedBytes,
- NULL
- );
- char m_pBuffer[1024] ="this is a test";
- int bRet = WriteFile(hHandle, m_pBuffer, sizeof(m_pBuffer),&dwReturnedBytes, NULL);
- if (!bRet) {
- CString s;
- s.Format(_T("%d"),::GetLastError());
- AfxMessageBox(s);
- return;
- }
复制代码
|
|