Visual Studio错误,正在获取设备GUID和路径名
Visual Studio errors and getting a device GUID and path name?
晚上大家好,我想知道是否有人能快速回答我两个问题。
我制作了一个与arm设备通信的应用程序,它运行良好,但当我移动PC等时,我需要重新配置设备路径。这是一个像下面这样的长的。
路径:\?usb#vid_045e&pid_0040#6&ff454f2&0&3#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
我做了一些阅读,发现它有两个特性SetupDiGetClassDevs
和SetupDiGetDeviceInstanceId
我需要。我的问题是,我是否在寻找正确的位置,即这两个函数是否会返回如上所述的路径。这个路径的技术名称是什么?
我在下面的微软网站上找到了一个我认为很好的例子(总是从例子中学到更好的东西),但这引发了错误C2440: '=' : cannot convert from 'HLOCAL' to 'LPTSTR'
哪一个是我的新指针错误?
这是代码
#include <stdio.h>
#include <windows.h>
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
int main( int argc, char *argv[ ], char *envp[ ] )
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevs(NULL,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return 1;
}
// Enumerate through all devices in Set.
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
&DeviceInfoData);i++)
{
DWORD DataT;
LPTSTR buffer = NULL;
DWORD buffersize = 0;
//
// Call function with null to begin with,
// then use the returned buffer size (doubled)
// to Alloc the buffer. Keep calling until
// success or an unknown failure.
//
// Double the returned buffersize to correct
// for underlying legacy CM functions that
// return an incorrect buffersize value on
// DBCS/MBCS systems.
//
while (!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
if (GetLastError() ==
ERROR_INSUFFICIENT_BUFFER)
{
// Change the buffer size.
if (buffer) LocalFree(buffer);
// Double the size to avoid problems on
// W2k MBCS systems per KB 888609.
buffer = LocalAlloc(LPTR,buffersize * 2); // ERROR LINE
}
else
{
// Insert error handling here.
break;
}
}
printf("Result:[%s]n",buffer);
if (buffer) LocalFree(buffer);
}
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
希望这很容易,谢谢。
您需要键入LocalAlloc()
:的返回值
buffer = (LPSTR) LocalAlloc(LPTR,buffersize * 2);
有关更多信息,请参阅MSDN上的LocalAlloc()文档。
相关文章:
- 从 GUID 获取 USB 卷路径
- C++ 写入路径名中包含不需要的空字符的文件
- ActiveDirectory/C++: 如何将 Guid 转换为用户名?
- 更改用于部署的凭据提供程序 GUID 的过程
- 如何在 std::p air 中使用 System::Guid 和自定义枚举?
- 将字符串强制转换为GUID并不能得到正确的结果
- 如何获得GUID编码器,如果我在IMFTransform上有一个指针?
- GUID variable for JPEG,BMP,PNG
- 如何在 C++ 中从 GUID 生成 SHA-1 字节数组
- 打开路径名中带有波浪号 (~) 的流
- 如何将Windows GUID转换为boost::uuid?
- Boost Ptree访问第一个元素,没有路径名
- 在 C++ 中填写 GUID 时出错
- C++ 通过 RegGetValue 读取机器 GUID
- 从多个进程和同一进程中注册同一ETW TraceLogging提供程序GUID
- 这是生成GUID的可靠方式
- Microsoft Guid guid serialization使用Boost序列化
- 使用 boost 解析符号链接时,结果不等于原始路径名
- Xalanc转换错误:无法确定文件的基本路径名(,第0,第0列)
- Visual Studio错误,正在获取设备GUID和路径名