size of SP_DEVICE_INTERFACE_DETAIL_DATA structure in vb.net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
this structures size gives a lot of problems reading on the www.
it is defined at http://msdn.microsoft.com/en-us/library/windows/hardware/ff552342(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/hardware/ff552342(v=vs.85).aspx

there is a lot of confusion about its size and how to set it. maybe this is why there are different drivers for 32 and 64 bit systems.
i work on a 64 bit windows 7 machine


to use this structure in vb.net you have to import it from unmanaged dlls. i found 2 examples:
from this forum : http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/4cf05588-ff55-4f38-9ebc-842eba9447c0/
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/4cf05588-ff55-4f38-9ebc-842eba9447c0/
<span style="color:green SP_DEVICE_INTERFACE_DETAIL_DATA<br/>
<span style="color:black <StructLayout(LayoutKind.Sequential, Pack:=1)> _<br/>
<span style="color:blue Public<span style="color:black
<span style="color:blue Structure<span style="color:black DeviceInterfaceDetailData<br/>
<span style="color:blue Public<span style="color:black MySize
<span style="color:blue As<span style="color:black <span style="color:blue Integer<br/>
<span style="color:black
<span style="color:blue Public<span style="color:black DevicePath
<span style="color:blue As<span style="color:black <span style="color:blue Short<br/>
<span style="color:black
<span style="color:blue Public<span style="color:black <span style="color:blue Sub<span style="color:black Initialize()<br/>
<span style="color:blue Me<span style="color:black .MySize = Marshal.SizeOf(<span style="color:blue GetType<span style="color:black (DeviceInterfaceDetailData))<br/>
<span style="color:blue End<span style="color:black
<span style="color:blue Sub<br/>
<span style="color:black <span style="color:blue End<span style="color:black
<span style="color:blue Structure<br/>

from http://code.google.com/p/usb-devices-list/downloads/detail?name=USBDevicesList_source.rar&can=2&q
http://code.google.com/p/usb-devices-list/downloads/detail?name=USBDevicesList_source.rar&can=2&q =<span style="color:blue
<pre class="prettyprint /// <summary>
/// Access to the path for a device
/// </summary>
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
public struct DeviceInterfaceDetailData
{
public int Size;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 256 )]
public string DevicePath;
}[/code]
from http://www.developerfusion.com/article/84338/making-usb-c-friendly/
http://www.developerfusion.com/article/84338/making-usb-c-friendly/

the same as example 2 and translated to vb.net
<pre class="prettyprint lang-vb <summary>
Access to the path for a device
http://msdn.microsoft.com/en-us/library/windows/hardware/ff552343(v=vs.85).aspx
</summary>
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure DeviceInterfaceDetailData
Public Size As UInt32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
Public DevicePath As String
End Structure[/code]
with trial and error the correct size for me is 8 , but what for 8 i still dont know 32 bit should be 5 .
if i use
<pre class="prettyprint lang-vb Dim oDetail As New DeviceInterfaceDetailData()
oDetail.MySize = Marshal.SizeOf(oDetail)[/code]
this Mysize is only 8 if i set the devicepath property type to UInt32 thus not a string which it should become. if i use example 2 or 3 i get a size of 260

the code gives no error but doesnt work because it doesnt produce a devicepathstring
example 1 uses a short , i dont know why but it comes near the correct size. because i cant get a devicepath out of a short , neither out of a Uint32 or is it a kind of pointer ?
so is the only way
<pre class="prettyprint oDetail.mysize = 8[/code]
the only solution ?
this following sentence i found a lot in projects using hid or usb devices ( for 32 bit systems i think):
<span style="font-size:small <span style="font-size:small
oDetail.Size = 5;



<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small // hardcoded to 5! Sorry, but this works and trying more future proof versions by setting the size to the struct sizeof
failed miserably. If you manage to sort it, mail me! Thx
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small



















<
nattelip
<br/>

<br/>


View the full article
 
Back
Top