TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kyau8
NA
1
0
SetupDiGetDeviceInterfaceDetail problem in C#
Feb 16 2006 8:03 PM
I am trying to communicate with USB via the setupapi.dll APIs. I have no problem calling SetupDiGetClassDevs, SetupDiEnumDeviceInterfaces, and the first call of SetupDiGetDeviceInterfaceDetail. But my second call of the SetupDiGetDeviceInterfaceDetail does not return the device path. Here is part of my C# code:
[StrucLayout( LayoutKind.Sequential, Pack = 1)]
public class DeviceInterfaceDetailData
{
public Int32 cbSize;
[MarshalAs( UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] devicePath;
}
...
[DllImport( "setupapi.dll" )]
public static extern Boolean SetupDiGetDeviceInterfaceDetail(
IntPtr deviceInformationSet,
DeviceInterfaceData deviceInterfaceData,
IntPtr deviceInterfaceDetailData,
Int32 deviceInterfaceDetailDataSize,
ref Int32 requiredSize,
IntPtr deviceInfoData );
...
// After first call to SetupDiGetDeviceInterfaceDetail, it returns a requiredSize of 84.
...
IntPtr buffer = Marshal.AllocHGlobal( requiredSize );
DeviceInterfaceDetailData detailData = new DeviceInterfaceDetailData();
detailData.cbSize = Marshal.SizeOf( detailData ); // cbSize = 5
detailData.devicePath = new byte[ requiredSize-4 ];
Marshal.StructureToPtr( detailData, buffer, false );
if ( SetupDiGetDeviceInterfaceDetail( deviceInfoSet, deviceInterfaceData, buffer, requiredSize, ref requiredSize, IntPtr.Zero ) == false )
{
return false;
}
// after this call, buffer does not contain the device path.
IntPtr pDevicePath = (IntPtr)((int)buffer + 4);
string deviceName = Marshal.PtrToStringAuto( pDevicePath );
Any help would be greatly appreciated!!
Reply
Answers (
1
)
how to compare date today with another date