Click here to Skip to main content
15,900,481 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Print Driver Pin
cobyjone2-Jul-04 2:17
cobyjone2-Jul-04 2:17 
GeneralRe: C# Print Driver Pin
Dave Kreskowiak2-Jul-04 3:25
mveDave Kreskowiak2-Jul-04 3:25 
QuestionPocket PC database access ? Pin
Christian Graus1-Jul-04 12:31
protectorChristian Graus1-Jul-04 12:31 
AnswerRe: Pocket PC database access ? Pin
Anders Molin1-Jul-04 13:54
professionalAnders Molin1-Jul-04 13:54 
GeneralRe: Pocket PC database access ? Pin
Christian Graus1-Jul-04 13:58
protectorChristian Graus1-Jul-04 13:58 
GeneralRe: Pocket PC database access ? Pin
Anders Molin1-Jul-04 13:59
professionalAnders Molin1-Jul-04 13:59 
GeneralRe: Pocket PC database access ? Pin
Heath Stewart2-Jul-04 2:18
protectorHeath Stewart2-Jul-04 2:18 
GeneralSetupDiGetDeviceInterfaceDetail driving me mad! Pin
Pain_Elemental1-Jul-04 10:22
Pain_Elemental1-Jul-04 10:22 
I'm still trying to get this SetupDiGetDeviceInterfaceDetail function to work in C#.

I am using these definitions now:
		[StructLayout(LayoutKind.Sequential)]
			public class SP_DEVICE_INTERFACE_DATA  // name doesn't matter - keep it simple
		{
			public uint cbSize;
			public Guid InterfaceClassGuid;
			public uint Flags;
			public IntPtr Reserved;
			// If you want, a helpful ctor
//			public SP_DEVICE_INTERFACE_DATA (uint cbSize, Guid InterfaceClassGuid,
//				uint Flags)
//			{
//				this.cbSize = cbSize;
//				this.InterfaceClassGuid = InterfaceClassGuid;
//				this.Flags = Flags;
//				this.Reserved = IntPtr.Zero;
//			}
		}
 
		[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
			public class SP_DEVICE_INTERFACE_DETAIL_DATA 
		{
			public uint cbSize;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=1)]
			public string DevicePath; // Or public char DevicePath should work
		}
 
		[StructLayout(LayoutKind.Sequential)]
			public class SP_DEVINFO_DATA
		{
			// Actually, you can reuse SpDeviceInterfaceData - their declaration
			// is the same, but I'll type this out anyway...
			public uint cbSize;
			public Guid ClassGuid;
			public uint DevInst;
			public IntPtr Reserved;
		}
 
		[DllImport("setupapi.dll")]
		public static extern bool SetupDiGetDeviceInterfaceDetail(
			IntPtr DeviceInfoSet,
			ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
			out SP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData,
			uint DeviceInterfaceDetailDataSize,
			out uint RequiredSize,
			out SP_DEVINFO_DATA DeviceInfoData);



Ok, the MSDN Library tells me this:

Using the SetupDiGetDeviceInterfaceDetail function to get details about an interface is typically a two-step process:


1. Get the required buffer size. Call SetupDiGetDeviceInterfaceDetail with a NULL DeviceInterfaceDetailData pointer, a DeviceInterfaceDetailDataSize of zero, and a valid RequiredSize parameter. In response to such a call, this function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the RequiredSize parameter receives the required buffer size.

2. Allocate an appropriately sized buffer and call the function again to get the interface details.

The interface details returned by this function include a device path that can be passed to functions such as CreateFile. Do not attempt to parse the device path symbolic name. Note that the device path can be reused after the system is rebooted.

The SetupDiGetDeviceInterfaceDetail function can be used to get only the DeviceInfoData parameter. If the interface exists but the DeviceInterfaceDetailData parameter is NULL, the function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the DeviceInfoData structure is filled with information about the device that exposes the interface.


Now this is what I am doing:
// First get size of required buffer for detailed information
Win32APIfunctions.SP_DEVICE_INTERFACE_DATA devInterfaceData = new Interfaces.Win32APIfunctions.SP_DEVICE_INTERFACE_DATA();
devInterfaceData.cbSize = (uint)Marshal.SizeOf(devInterfaceData);

Win32APIfunctions.SP_DEVICE_INTERFACE_DETAIL_DATA devInterfaceDetailData = null;

Win32APIfunctions.SP_DEVINFO_DATA devInfoData = null;

uint uiRequiredSize=0;
Win32APIfunctions.SetupDiGetDeviceInterfaceDetail(NewDeviceInfoSet, ref devInterfaceData, out devInterfaceDetailData, 0, out uiRequiredSize, out devInfoData);

int iLastError = Marshal.GetLastWin32Error();



I always get errorcode 1421 ERROR_CONTROL_ID_NOT_FOUND.


It's driving my mad! Everything looks correct to me Cry | :((

-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
GeneralRe: SetupDiGetDeviceInterfaceDetail driving me mad! Pin
leppie1-Jul-04 12:17
leppie1-Jul-04 12:17 
GeneralRe: SetupDiGetDeviceInterfaceDetail driving me mad! Pin
Pain_Elemental1-Jul-04 19:46
Pain_Elemental1-Jul-04 19:46 
GeneralRe: SetupDiGetDeviceInterfaceDetail driving me mad! Pin
Pain_Elemental3-Jul-04 21:49
Pain_Elemental3-Jul-04 21:49 
GeneralA question about object sender Pin
Member 9401251-Jul-04 9:01
Member 9401251-Jul-04 9:01 
GeneralRe: A question about object sender Pin
Karl 20001-Jul-04 10:12
Karl 20001-Jul-04 10:12 
GeneralRe: A question about object sender Pin
Member 9401251-Jul-04 10:34
Member 9401251-Jul-04 10:34 
GeneralCalling UI Thread Pin
WKIII1-Jul-04 8:59
WKIII1-Jul-04 8:59 
GeneralRe: Calling UI Thread Pin
Heath Stewart2-Jul-04 2:37
protectorHeath Stewart2-Jul-04 2:37 
GeneralRe: Calling UI Thread Pin
WKIII6-Jul-04 10:18
WKIII6-Jul-04 10:18 
GeneralSenior C# Programmer Pin
MikeHarris1-Jul-04 8:55
MikeHarris1-Jul-04 8:55 
GeneralRe: Senior C# Programmer Pin
Colin Angus Mackay1-Jul-04 12:26
Colin Angus Mackay1-Jul-04 12:26 
GeneralSetting application icon doesnt work Pin
Anonymous1-Jul-04 8:12
Anonymous1-Jul-04 8:12 
GeneralRe: Setting application icon doesnt work Pin
Karl 20001-Jul-04 10:20
Karl 20001-Jul-04 10:20 
GeneralRe: Setting application icon doesnt work Pin
leppie1-Jul-04 12:22
leppie1-Jul-04 12:22 
GeneralRe: Setting application icon doesnt work Pin
Anonymous2-Jul-04 1:16
Anonymous2-Jul-04 1:16 
General.Net Remoting return Object help Pin
bmasephol1-Jul-04 7:19
bmasephol1-Jul-04 7:19 
GeneralRe: .Net Remoting return Object help Pin
Judah Gabriel Himango1-Jul-04 7:57
sponsorJudah Gabriel Himango1-Jul-04 7:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.