[Windows Mobile Development and Hacking General] zevallos:
I'm using VB.Net for Windows Mobile 5, but still not working

I want to use the GPS Intermediate Driver because I want to let the GPS to be used for other apps, such as the Google Maps for WM and other.

I did the following code, but I still not getting the right result... I did a program using the Serial connection, but Google Maps and other cannot use the GPS at the same time.

So... what am I doing wrong?

Here my code, any clues?

REM Declare Function GPSOpenDevice Lib "gpsapi.dll" (ByVal hNewLocationData As IntPtr, ByVal hDeviceStateChange As IntPtr, ByVal szDeviceName As String, ByVal dwFlags As Integer) As IntPtr

<DllImport("gpsapi.dll", EntryPoint:="GPSOpenDevice", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _

Public Shared Function GPSOpenDevice(ByVal hNewLocationData As IntPtr, ByVal hDeviceStateChange As IntPtr, ByVal szDeviceName As String, ByVal dwFlags As Integer) As IntPtr

End Function

REM Declare Function GPSCloseDevice Lib "gpsapi.dll" (ByVal hGPSDevice As IntPtr) As Integer

<DllImport("gpsapi.dll", EntryPoint:="GPSCloseDevice", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _

Public Shared Function GPSCloseDevice(ByVal hGPSDevice As IntPtr) As Integer

End Function

REM Declare Function GPSGetDeviceState Lib "gpsapi.dll" (ByVal pGPSDevice As IntPtr) As Integer

<DllImport("gpsapi.dll", EntryPoint:="GPSGetDeviceState", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _

Public Shared Function GPSGetDeviceState(ByVal pGPSDevice As IntPtr) As Integer

End Function

REM Declare Function GPSGetPosition Lib "gpsapi.dll" (ByVal hGPSDevice As IntPtr, ByVal pGPSPosition As IntPtr, ByVal dwMaximumAge As Integer, ByVal dwFlags As Integer) As Integer

<DllImport("gpsapi.dll", EntryPoint:="GPSGetPosition", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _

Public Shared Function GPSGetPosition(ByVal hGPSDevice As IntPtr, ByVal pGPSPosition As GPS_POSITION, ByVal dwMaximumAge As Integer, ByVal dwFlags As Integer) As Integer

End Function

Const dwSize As Long = 0

Const dwVersion As Long = 1

Const dwFlags As Long = 0

Const dwValidFields As Long = 0

Const GPS_MAX_SATELLITES As Long = 12

<StructLayout(LayoutKind.Sequential)> Public Structure GPS_POSITION

Dim dwVersion As Long

Dim dwSize As Long

Dim dwValidFields As Long

Dim dwFlags As Long

'Dim stUTCTime As systemtime

Dim dblLatitude As Double

Dim dblLongitude As Double

Dim flSpeed As Double

Dim flHeading As Double

Dim dblMagneticVariation As Double

Dim flAltitudeWRTSeaLevel As Single

Dim flAltitudeWRTEllipsoid As Single

'GPS_FIX_QUALITY FixQuality;

'GPS_FIX_TYPE FixType;

'GPS_FIX_SELECTION SelectionType;

Dim flPositionDilutionOfPrecision As Single

Dim flHorizontalDilutionOfPrecision As Single

Dim flVerticalDilutionOfPrecision As Single

Dim dwSatelliteCount As Long

Dim rgdwSatellitesUsedPRNs() As Long

Dim dwSatellitesInView As Long

Dim rgdwSatellitesInViewPRNs() As Long

Dim rgdwSatellitesInViewElevation() As Long

Dim rgdwSatellitesInViewAzimuth() As Long

Dim rgdwSatellitesInViewSignalToNoiseRatio() As Long

End Structure

Enum GPS_FIX_QUALITY

GPS_FIX_QUALITY_UNKNOWN

GPS_FIX_QUALITY_GPS

GPS_FIX_QUALITY_DGPS

End Enum

Enum GPS_FIX_TYPE

GPS_FIX_UNKNOWN

GPS_FIX_2D

GPS_FIX_3D

End Enum

Enum GPS_FIX_SELECTION

GPS_FIX_SELECTION_UNKNOWN

GPS_FIX_SELECTION_AUTO

GPS_FIX_SELECTION_MANUAL

End Enum

<StructLayout(LayoutKind.Sequential)> Public Structure SYSTEMTIME

Public wYear As Short

Public wMonth As Short

Public wDayOfWeek As Short

Public wDay As Short

Public wHour As Short

Public wMinute As Short

Public wSecond As Short

Public wMilliseconds As Short

End Structure

Dim gpsHandle As IntPtr = IntPtr.Zero

Public Function OpenGPSDevice() As Boolean

Try

gpsHandle = GPSOpenDevice(Nothing, Nothing, Nothing, 0)

OpenGPSDevice = (gpsHandle <> 0)

MsgBox("Device is open")

Catch ex As Exception

MsgBox("Error opening GPSDevice")

End Try

End Function

Public Function CloseGPSDevice() As Boolean

Try

If gpsHandle = 0 Then Exit Function

GPSCloseDevice(gpsHandle)

gpsHandle = IntPtr.Zero

MsgBox("Device is closed")

Catch ex As Exception

MsgBox("Error closing GPSDevice")

End Try

End Function

Private Sub bmtGPS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmtGPS.Click

Dim i As Long

Dim gpsPOS As New GPS_POSITION

Try

'gpsPOS.dwVersion = "GPS_VERSION_1"

'gpsPOS.dwSize = 512

i = GPSGetPosition(gpsHandle, gpsPOS, 500000, 0)

txtTeste.Text &= i

txtTeste.Text &= vbCrLf & "Latitude=" & gpsPOS.dblLatitude

txtTeste.Text &= vbCrLf & "Longitude=" & gpsPOS.dblLongitude

txtTeste.Text &= vbCrLf & "SatelliteCount=" & gpsPOS.dwSatelliteCount

txtTeste.Text &= vbCrLf & "SatellitesInView=" & gpsPOS.dwSatellitesInView

txtTeste.Text &= vbCrLf & "Heading=" & gpsPOS.flHeading

txtTeste.Text &= vbCrLf & "Speed=" & gpsPOS.flSpeed

txtTeste.Text &= vbCrLf & "Flags=" & gpsPOS.dwFlags

Catch ex As Exception

MsgBox("Error getting position")

End Try

End Sub

Private Sub bmtGPSOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmtGPSOn.Click

OpenGPSDevice()

End Sub

Private Sub bmtGPSOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmtGPSOff.Click

CloseGPSDevice()

End Sub