최근, 나는 HID 장치를 얻기 위해 C# .NET을 사용하고자하는 이상한 문자열을 얻을 것이다. 그러나 나는 약간의 문제를 만난다.C 번호 - SetupDiGetDeviceInterfaceDetail은
내가 SetupDiGetDeviceInterfaceDetail() 함수를 사용하는 경우, 내가 잘못된 경로를 얻을 것이다. 아래의 get 경로 기능의
는내 코드입니다.
private string GetDevicePath(IntPtr hDeviceInfo, ref SP_DEVICE_INTERFACE_DATA devInterfaceData)
{
uint nRequiredSize = 0;
//basically, the first device detailed will return the false... it the really thing.
if (!SetupDiGetDeviceInterfaceDetail(hDeviceInfo, ref devInterfaceData, IntPtr.Zero, (uint)0, ref nRequiredSize, IntPtr.Zero))
{
///Declare Sample 3:
SP_DEVICE_INTERFACE_DETAIL_DATA oDevInterfaceDetailedData = new SP_DEVICE_INTERFACE_DETAIL_DATA();
//Create Buffer to save the path detailed.
oDevInterfaceDetailedData.cbSize = 5; //=5
///With Sample 3:
if (SetupDiGetDeviceInterfaceDetail(hDeviceInfo, ref devInterfaceData,ref oDevInterfaceDetailedData, nRequiredSize, ref nRequiredSize, IntPtr.Zero))
{
//FIXME: Problem 1: The CreateFile will return 123. its means The filename, directory name, or volume label syntax is incorrect.
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
///With Sample 3:
Log.Text += ("Acutal Path = "+ oDevInterfaceDetailedData.DevicePath + "\n");
return oDevInterfaceDetailedData.DevicePath;
}
}
return null;
}
문제는 여기에 있습니다 : oDevInterfaceDetailedData.DevicePath
변수의 뜻은 아래와 같은 메시지를 표시 문자열입니다.
[DllImport("setupapi.dll", SetLastError = true)]
protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr lpDeviceInfoSet, ref SP_DEVICE_INTERFACE_DATA oInterfaceData, ref SP_DEVICE_INTERFACE_DETAIL_DATA lpDeviceInterfaceDetailData, uint nDeviceInterfaceDetailDataSize, ref uint nRequiredSize, IntPtr lpDeviceInfoData);
[DllImport("setupapi.dll", SetLastError = true)]
protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr lpDeviceInfoSet, ref SP_DEVICE_INTERFACE_DATA oInterfaceData, IntPtr lpDeviceInterfaceDetailData, uint nDeviceInterfaceDetailDataSize, ref uint nRequiredSize, IntPtr lpDeviceInfoData);[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SP_DEVICE_INTERFACE_DETAIL_DATA
{
public uint cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DevicePath;
}
내 플랫폼 아래와 같은 기능/구조
Acutal Path = 屜尿楨⍤楶彤㌰て瀦摩ㅟ㐰⌱☶㐱㡡㈶搷〦〦〰⌰㑻ㅤ㕥戵ⴲㅦ昶ㄭ挱ⵦ㠸扣〭ㄱ〱〰㌰細
내 선언 64 비트 윈도우 OS이다. VS2017 IDE를 사용하여 C#에서 WPF 프로젝트를 빌드합니다. ,
[같이 DllImport ("setupapi.dll"@ 캐릭터 세트를 :
는
내 비밀 디코더 링'\\\\? \\ HID #의 vid_03f0 & pid_1041 # 6 14a8627d & 0 & 0000 # {4d1e55b2-f16f-11CF로 그것을 켤 수 있습니다 ... 대신 자동차의 ANSI를 사용해야합니다 -88cb-001111000030}'. 더 좋아 보인다. [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Unicode])를 구조체 선언에 적용하고 마찬가지로 [DllImport] 선언에 CharSet을 추가합니다. –
좋습니다. 나는 charset을 시도 할 것이다 .... 그리고 비밀 디코더는 무엇입니까 ?? (호기심이 – Smallben