[Windows Mobile Software Development] harddisk_wp:
Solved that one. Now during run w/ this code, I get a NotSupported exception in updateData():

Imports System.Runtime.InteropServices

Public Class clsCompass
<DllImport("coredll.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Private Shared Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As System.UInt32, ByVal dwShareMode As System.UInt32, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As System.UInt32, ByVal dwFlagsAndAttributes As System.UInt32, ByVal hTemplateFile As IntPtr) As Integer
End Function
<DllImport("coredll.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Private Shared Function RegisterService(ByVal lpszType As String, ByVal dwIndex As System.UInt32, ByVal lpszLib As String, ByVal dwInfo As System.UInt32)
End Function
<DllImport("coredll.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> Public Shared Function DeviceIoControl(<[In]()> ByVal hDevice As Integer, <[In]()> ByVal dwIoControlCode As Integer, <[In]()> ByRef nInputBuffer As Integer, <[In]()> ByVal nInBufferSize As Integer, <Out()> ByVal lpOutBuffer As compass_data, <[In]()> ByVal nOutBufferSize As Integer, <Out()> ByRef lpBytesReturned As Integer, <[In]()> ByVal lpOverlapped As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("coredll.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> Public Shared Function DeviceIoControl(<[In]()> ByVal hDevice As Integer, <[In]()> ByVal dwIoControlCode As Integer, <[In]()> ByRef nInputBuffer As Integer, <[In]()> ByVal nInBufferSize As Integer, <Out()> ByVal lpOutBuffer As Integer, <[In]()> ByVal nOutBufferSize As Integer, <Out()> ByRef lpBytesReturned As Integer, <[In]()> ByVal lpOverlapped As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function

Const DIO_INIT As Int32 = &H3000001
Const DIO_READ As Int32 = &H3000003
Const DIO_QUIT As Int32 = &H3000002
Const INVALID_HANDLE_VALUE As Int64 = -1

Structure compass_data
Public x As Short
Public y As Short
Public z As Short
Public angle As Short
Public d As Short
Public dummy As String
End Structure
Overrides Function toString() As String
Return "X: " + compassData.x + vbNewLine _
+ "X: " + compassData.x + vbNewLine _
+ "Y: " + compassData.y + vbNewLine _
+ "Z: " + compassData.z + vbNewLine _
+ "a: " + compassData.angle + vbNewLine _
+ "d: " + compassData.d + vbNewLine
End Function

Private devHandle As Integer
Private srvHandle As Integer
Public compassData As New compass_data
Public Function initCompass()
devHandle = CreateFile("SEN0:", 0, 0, 0, 3, &H80, 0)
If devHandle = INVALID_HANDLE_VALUE Or devHandle = 0 Then
devHandle = 0
srvHandle = RegisterService("SEN", 0, "HTCSensorService.dll", 1)
If srvHandle = 0 Then Return False
devHandle = CreateFile("SEN0:", 0, 0, 0, 3, &H80, 0)
If devHandle = INVALID_HANDLE_VALUE Or devHandle = 0 Then Return False
End If
If DeviceIoControl(devHandle, DIO_INIT, 0, 0, 0, 0, 0, 0) = 0 Then Return False
Return True
End Function
Public Function updateData()
Dim readBytes As System.UInt32
If devHandle = 0 Then Return False
If DeviceIoControl(devHandle, DIO_READ, 0, 0, compassData, 0, readBytes, 0) = 0 Then
Return False
Else
Return True
End If
End Function
Public Function shutdownCompass()
If devHandle <> 0 Then
If DeviceIoControl(devHandle, DIO_QUIT, 0, 0, 0, 0, 0, 0) = 0 Then
Return False
Else
Return True
End If
End If
Return True
End Function
End Class

System.NotSupportedException was unhandled

Message="NotSupportedException"

StackTrace:

bei GPSLib.clsCompass.updateData() bei GPSLib.frmMain.Timer1_Tick(Object sender, EventArgs e) bei System.Windows.Forms.Timer._WnProc(WM wm, Int32 wParam, Int32 lParam) bei System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(WM wm, Int32 wParam, Int32 lParam) bei Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain) bei System.Windows.Forms.Application.Run(Form fm) bei GPSLib.frmMain.Main()

InnerException: