// This will print current location private void button4_Click(object sender, EventArgs e) { //Here will be code for location label1.Text = "Locating....."; // Prepare GpsPosition struct GpsPosition coordinates = new GpsPosition(); coordinates.dwVersion = 1; coordinates.dwSize = Marshal.SizeOf(typeof(GpsPosition)); IntPtr position = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GpsPosition))); // Marshal our data to the native pointer we allocated. Marshal.StructureToPtr(coordinates, position, false); GPSGetPosition(device, position, 10000, 0); try { if (position != IntPtr.Zero) { coordinates = (GpsPosition)Marshal.PtrToStructure(position, typeof(GpsPosition)); label1.Text = "Position: " + coordinates.Latitude + "," + coordinates.Longitude; } else { label1.Text = "Position is null!"; } } catch (Exception ex) { label1.Text = ex.Message; } // Marshal.FreeHGlobal(position); }