?
?dotnet
I want to get a different ID on every different device.Please help me,and
Thanks.
Thanks.
Mohammad Abu Sharkh said:see this
Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByVal dwIoControlCode As
Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As Int32, ByVal lpOutBuf()
As Byte, ByVal nOutBufSize As Int32, ByRef lpBytesReturned As Int32) As
Boolean
'
' TODO: Add any constructor code after InitializeComponent call
'
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101
Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A
Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 * FILE_DEVICE_HAL)
Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or METHOD_BUFFERED
Public Shared Function GetDeviceID() As String
' Initialize the output buffer to the size of a Win32 DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False
Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look at
' this field rather than the nOutBufSize param of KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0
' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outbuff,
nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on
this device", New Win32Exception([error]))
Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data. The required size
' is in the first 4 bytes of the output buffer (DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
Case Else
Throw New Win32Exception([error], "Unexpected error")
End Select
End If
End While
Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff, &H4) '
DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff, &H8) '
DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 = BitConverter.ToInt32(outbuff, &HC) '
DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff, &H10) '
DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer
For i = dwPresetIDOffset To (dwPresetIDOffset + dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset + dwPlatformIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
Return sb.ToString()
End Function
End Class
?dotnet said:I want to get a different ID on every different device.Please help me,and
Thanks.
Pawel Achtel said:I have reported a bug some time ago that in some models of IPAQs this API
simply doesn't work.
Kind Regards,
Pawel Achtel
3D Software Development, Australia
www.24x7.com.au
dwIoControlCodeMohammad Abu Sharkh said:see this
Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByValAs
Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As Int32, ByVal lpOutBuf()
As Byte, ByVal nOutBufSize As Int32, ByRef lpBytesReturned As Int32) As
Boolean
'
' TODO: Add any constructor code after InitializeComponent call
'
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101
Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A
Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 * FILE_DEVICE_HAL)
Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or METHOD_BUFFERED
Public Shared Function GetDeviceID() As String
' Initialize the output buffer to the size of a Win32 DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False
Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look at
' this field rather than the nOutBufSize param of KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0
' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outbuff,
nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on
this device", New Win32Exception([error]))
Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data. The required size
' is in the first 4 bytes of the output buffer (DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
Case Else
Throw New Win32Exception([error], "Unexpected error")
End Select
End If
End While
Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff, &H4) '
DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff, &H8) '
DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 = BitConverter.ToInt32(outbuff, &HC) '
DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff, &H10) '
DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer
For i = dwPresetIDOffset To (dwPresetIDOffset + dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset + dwPlatformIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
Return sb.ToString()
End Function
End Class
?dotnet said:I want to get a different ID on every different device.Please help me,and
Thanks.
Timothy Taylor said:Mohammad or Chris, when i use this code it says that "Marshal" and
"DEVICE_ID" aren't declared.
What do i have to import to get them?
Thanks,
-Tim
dwIoControlCodeMohammad Abu Sharkh said:see this
Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByValAs
Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As Int32, ByVal lpOutBuf()
As Byte, ByVal nOutBufSize As Int32, ByRef lpBytesReturned As Int32) As
Boolean
'
' TODO: Add any constructor code after InitializeComponent call
'
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101
Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A
Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 * FILE_DEVICE_HAL)
Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or METHOD_BUFFERED
Public Shared Function GetDeviceID() As String
' Initialize the output buffer to the size of a Win32 DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False
Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look at
' this field rather than the nOutBufSize param of KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0
' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outbuff,
nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New NotSupportedException("IOCTL_HAL_GET_DEVICEID is not supported on
this device", New Win32Exception([error]))
Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data. The required size
' is in the first 4 bytes of the output buffer (DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
Case Else
Throw New Win32Exception([error], "Unexpected error")
End Select
End If
End While
Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff, &H4) '
DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff, &H8) '
DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 = BitConverter.ToInt32(outbuff, &HC) '
DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff, &H10) '
DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer
For i = dwPresetIDOffset To (dwPresetIDOffset + dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset + dwPlatformIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
Return sb.ToString()
End Function
End Class
?dotnet said:I want to get a different ID on every different device.Please help me,and
Thanks.
Mohammad Abu Sharkh said:I sent the class for you in Email
dwPlatformIDSize) -Timothy Taylor said:Mohammad or Chris, when i use this code it says that "Marshal" and
"DEVICE_ID" aren't declared.
What do i have to import to get them?
Thanks,
-Tim
dwIoControlCodeMohammad Abu Sharkh said:see this
Public Class DeviceID
Declare Function KernelIoControl Lib "CoreDll.dll" (ByValsupportedAs
Int32, ByVal lpInBuf As IntPtr, ByVal nInBufSize As Int32, ByVal lpOutBuf()
As Byte, ByVal nOutBufSize As Int32, ByRef lpBytesReturned As Int32) As
Boolean
'
' TODO: Add any constructor code after InitializeComponent call
'
Private Shared METHOD_BUFFERED As Int32 = 0
Private Shared FILE_ANY_ACCESS As Int32 = 0
Private Shared FILE_DEVICE_HAL As Int32 = &H101
Private Const ERROR_NOT_SUPPORTED As Int32 = &H32
Private Const ERROR_INSUFFICIENT_BUFFER As Int32 = &H7A
Private Shared IOCTL_HAL_GET_DEVICEID As Int32 = (&H10000 * FILE_DEVICE_HAL)
Or (&H4000 * FILE_ANY_ACCESS) Or (&H4 * 21) Or METHOD_BUFFERED
Public Shared Function GetDeviceID() As String
' Initialize the output buffer to the size of a Win32 DEVICE_ID structure
'
Dim outbuff(19) As Byte
Dim dwOutBytes As Int32
Dim done As Boolean = False
Dim nBuffSize As Int32 = outbuff.Length
' Set DEVICEID.dwSize to size of buffer. Some platforms look at
' this field rather than the nOutBufSize param of KernelIoControl
' when determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
dwOutBytes = 0
' Loop until the device ID is retrieved or an error occurs
'
While Not done
If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outbuff,
nBuffSize, dwOutBytes) Then
done = True
Else
Dim [error] As Integer = Marshal.GetLastWin32Error()
Select Case [error]
Case ERROR_NOT_SUPPORTED
Throw New NotSupportedException("IOCTL_HAL_GET_DEVICEID is not
onthis device", New Win32Exception([error]))
Case ERROR_INSUFFICIENT_BUFFER
' The buffer is not big enough for the data. The required size
' is in the first 4 bytes of the output buffer (DEVICE_ID.dwSize).
nBuffSize = BitConverter.ToInt32(outbuff, 0)
outbuff = New Byte(nBuffSize) {}
' Set DEVICEID.dwSize to size of buffer. Some
' platforms look at this field rather than the
' nOutBufSize param of KernelIoControl when
' determining if the buffer is large enough.
'
BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
Case Else
Throw New Win32Exception([error], "Unexpected error")
End Select
End If
End While
Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff, &H4) '
DEVICE_ID.dwPresetIDOffset
Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff, &H8) '
DEVICE_ID.dwPresetIDSize
Dim dwPlatformIDOffset As Int32 = BitConverter.ToInt32(outbuff, &HC) '
DEVICE_ID.dwPlatformIDOffset
Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff, &H10) '
DEVICE_ID.dwPlatformIDBytes
Dim sb As New StringBuilder
Dim i As Integer
For i = dwPresetIDOffset To (dwPresetIDOffset + dwPresetIDSize) - 1
sb.Append(String.Format("{0:X2}", outbuff(i)))
Next i
sb.Append("-")
For i = dwPlatformIDOffset To (dwPlatformIDOffset +
1