I am trying to use the GPS_DEVICE structure from within .NET CF 3.5 and I keep getting an error (87) returned from the call to GPSGetDeviceState
. As far as I know, 87 means invalid parameter, but I do not know which parameter is invalid!
Can anybody please advise to what I have done wrong with my code as I have now spent the best part of two nights getting nowhere.
The simple test case is...
NativeMethods.GpsDevice gpsDevice = new NativeMethods.GpsDevice();
int result = NativeMethods.GPSGetDeviceState(ref gpsDevice);
My interop is defined as follows...
private const string GpsApi = @"gpsapi.dll";
private const int GPS_VERSION_1 = 1;
private const int GPS_MAX_SATELLITES = 12;
private const int GPS_MAX_PREFIX_NAME = 16;
private const int GPS_MAX_FRIENDLY_NAME = 64;
[DllImport(GpsApi)]
public static extern int GPSGetDeviceState(ref GpsDevice pGPSDevice);
[StructLayout(LayoutKind.Sequential)]
public class GpsDevice {
public UInt32 dwVersion;
public UInt32 dwSize;
public IoctlServiceStatus dwServiceState;
public IoctlServiceStatus dwDeviceState;
public FileTime ftLastDataReceived;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NativeMethods.GPS_MAX_PREFIX_NAME)]
public string szGPSDriverPrefix;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NativeMethods.GPS_MAX_PREFIX_NAME)]
public string szGPSMultiplexPrefix;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NativeMethods.GPS_MAX_FRIENDLY_NAME)]
public string szGPSFriendlyName;
public GpsDevice() {
this.dwVersion = NativeMethods.GPS_VERSION_1;
this.dwSize = (UInt32)Marshal.SizeOf(this);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct FileTime {
UInt32 dwLowDateTime;
UInt32 dwHighDateTime;
}
public enum IoctlServiceStatus : uint {
Off = 0,
On = 1,
StartingUp = 2,
ShuttingDown = 3,
Unloading = 4,
Uninitialised = 5,
Unknown = 0xffffffff
}
I hope I have included all information that may be required; if not, please prompt me for more.
Thanks in advance.