阅读:1591回复:3
有关符号链接的问题
小弟是一新手,以前从没接触过windows 驱动,最近公司要求写一USB摄像头驱动。需要在win32环境中控制驱动的行为。通过查看资料写了一个示例程序,可是遇到一些问题。createfile调用后返回的值总是0xffffff,没有成功。
相关代码如下: 驱动: // {15C52BD8-0703-4a3b-B8F5-A3D237083B17} DEFINE_GUID(STK_USB_UPFILTER, 0x15c52bd8, 0x703, 0x4a3b, 0xb8, 0xf5, 0xa3, 0xd2, 0x37, 0x8, 0x3b, 0x17); /////////////////////////////////////////////////////// //register device interface status = IoRegisterDeviceInterface(PhysicalDeviceObject, &STK_USB_UPFILTER, NULL, &(deviceExtension->wstrIfSymLink)); if (!NT_SUCCESS(status)) { IoDeleteDevice(deviceObject); DebugPrint(("IoRegisterDeviceInterface fail status = %d.......\n", status)); return status; } //Enable device symlink status = IoSetDeviceInterfaceState(&(deviceExtension->wstrIfSymLink), TRUE); if (!NT_SUCCESS(status)) { IoDeleteDevice(deviceObject); DebugPrint(("IoSetDeviceInterfaceState fail status = %d.......\n", status)); return status; } DebugPrint(("enable symlink %ws........\n", (deviceExtension->wstrIfSymLink).Buffer)); ////////////////////////////////////////////////////////////////////////// 这里symlink 的输出是 \??\USB#Vid_174fPid_8a31MI_00#654942d6000000#{15c52bd8-0703-4a3b-b8f5-a3d237083b17} win32: //Get device interface HANDLE GetDeviceInterface(GUID* pGuid, DWORD dwInstance) { //Get handle to relevant device information set HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if (INVALID_HANDLE_VALUE == info) { printf("Not hdevinfo avaliable for this guid............\n"); return NULL; } //Get interface data for the requeseted instance SP_INTERFACE_DEVICE_DATA ifData; ZeroMemory(&ifData, sizeof(ifData)); ifData.cbSize = sizeof(ifData); if (!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, dwInstance, &ifData)) { printf("No spinterfacedevicedata available for this guid instance.........\n"); SetupDiDestroyDeviceInfoList(info); return NULL; } //get size of symbolink name DWORD dwReqLen = 0; SetupDiGetDeviceInterfaceDetail(info, &ifData, NULL, 0, &dwReqLen, NULL); if (0 == dwReqLen) { SetupDiDestroyDeviceInfoList(info); return NULL; } PSP_INTERFACE_DEVICE_DETAIL_DATA ifpDataDetail = reinterpret_cast<PSP_INTERFACE_DEVICE_DETAIL_DATA>(new char[dwReqLen]); if (NULL == ifpDataDetail) { SetupDiDestroyDeviceInfoList(info); return NULL; } //Get symlink name ifpDataDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if (!SetupDiGetDeviceInterfaceDetail(info, &ifData, ifpDataDetail, dwReqLen, NULL, NULL)) { SetupDiDestroyDeviceInfoList(info); delete ifpDataDetail; ifpDataDetail = NULL; return NULL; } printf("Symlink name is %s ...................\n", ifpDataDetail->DevicePath); // \\??\\USB#Vid_174fPid_8a31MI_00#654942d6000000#{15c52bd8-0703-4a3b-b8f5-a3d237083b17} char strDevice[] = "\\\\.\\USB#Vid_174fPid_8a31MI_00#654942d600000#{15c52bd8-0703-4a3b-b8f5-a3d237083b17}"; //char strDevice[] = "\\??\\USB#Vid_174fPid_8a31MI_00#654942d600000#{15c52bd8-0703-4a3b-b8f5-a3d237083b17}"; /* printf("Symlink name is %s ...................\n", ifpDataDetail->DevicePath); char strFileName[MAX_PATH]; ZeroMemory(strFileName, sizeof(strFileName)); char* p = strFileName; int i = 0; while (i < dwReqLen) { *p++ = ifpDataDetail->DevicePath; if ('\\' == ifpDataDetail->DevicePath) { *p++ = '\\'; //add '\' } ++i; } delete ifpDataDetail; ifpDataDetail = NULL; printf("strfilename = %s...............\n", strFileName); */ //openfile HANDLE hDevice = CreateFile(ifpDataDetail->DevicePath, //strDevice GENERIC_READ | GENERIC_WRITE, NULL, //FILE_SHARE_READ | FILE_SHARE_WRITE NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); //clean resources delete ifpDataDetail; ifpDataDetail = NULL; SetupDiDestroyDeviceInfoList(info); return hDevice; } 在win32中调用该函数后ifpDataDetail->DevicePath的值为:"\\?\usb#vid_174f&pid_8a31&mi_00#6&54942d6&0&0000#{15c52bd8-0703-4a3b-b8f5-a3d237083b17}" 与symlink中的值不一样。我尝试在CreateFile中用strDevice代替ifpDataDetail->DevicePath,还有//add '\'返回值还是0xffffffff. 小弟初次接触windows驱动,希望大侠能够指点指点。 |
|
沙发#
发布于:2008-09-27 13:40
先自己顶下
|
|
板凳#
发布于:2008-10-13 10:22
怎么没人回答呀!@!!!!
|
|
地板#
发布于:2008-10-13 14:56
问题已解决,没有正确处理create irp
|
|