From: Kevin FL on
Roger - did you ever figure out anything on this?

"Roger Vincent" wrote:

> We found that on WM5 devices when we went into unattended mode we had to
> issue a IOCTL_SERVICE_STOP / IOCTL_SERVICE_START to get GPS going again as it
> stoped as soon as we went into unattended mode.
>
> On WM6 devices we get an error (device is an O2 XDA Orbit 2 aka HTC Polaris
> aka HTC Touch Cruise). The last error value after the DeviceIoControl call
> is 4319 'device not ready for use'.
>
> relevant .NET code snippet with PInvoke declarations as follows (this gets
> called when we get notified that the device has entered the unattended power
> state):
>
> [DllImport("coredll", SetLastError = true)]
> static extern IntPtr CreateFile(String lpFileName,
> [MarshalAs(UnmanagedType.U4)]FileAccess fileaccess,
> [MarshalAs(UnmanagedType.U4)]FileShare fileshare, IntPtr
> lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)]FileMode
> creationdisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);
>
> [DllImport("coredll.dll", EntryPoint = "DeviceIoControl",
> SetLastError = true)]
> internal static extern int DeviceIoControlCE(
> IntPtr hDevice,
> uint dwIoControlCode,
> IntPtr lpInBuffer,
> int nInBufferSize,
> IntPtr lpOutBuffer,
> int nOutBufferSize,
> ref int lpBytesReturned,
> IntPtr lpOverlapped);
>
> [DllImport("coredll", SetLastError = false)]
> static extern ulong GetLastError();
>
>
> [DllImport("coredll.dll", SetLastError = true, CallingConvention =
> CallingConvention.Winapi, CharSet = CharSet.Auto)]
> [return: MarshalAs(UnmanagedType.Bool)]
> public static extern bool CloseHandle(IntPtr hObject);
>
> public const uint IOCTL_SERVICE_START = 0x41000004;
> public const uint IOCTL_SERVICE_STOP = 0x41000008;
> public const uint IOCTL_SERVICE_REFRESH = 0x4100000C;
> public const uint IOCTL_SERVICE_STATUS = 0x41000020;
>
> IntPtr deviceHandle = CreateFile("GPD0:", FileAccess.Read,
> FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
> int numBytesReturned = 0;
> int result = 0;
> int lastError = 0;
> result = DeviceIoControlCE(deviceHandle, IOCTL_SERVICE_STOP,
> IntPtr.Zero, 0, IntPtr.Zero, 0, ref numBytesReturned,
> IntPtr.Zero);
> if(result==0)
> {
> lastError = Marshal.GetLastWin32Error();
> }
> Thread.Sleep(5000);
> result = DeviceIoControlCE(deviceHandle, IOCTL_SERVICE_START,
> IntPtr.Zero, 0, IntPtr.Zero, 0, ref numBytesReturned,
> IntPtr.Zero);
> if (result == 0)
> {
> lastError = Marshal.GetLastWin32Error();
> }
>
> We've also tried a call to SetPowerRequirement on GPD0: with
> DevicePowerState DO prior to the CreateFile on GPD0: and that seems to have
> the effect of changing the Win32 error code to 21 "The device is not ready.",
> rather than 4319 "The device is not ready for use. "
>
> Any thoughts, suggestions, or especially fixes are welcome.
From: Roger Vincent on
Hi Kevin,
We haven't yet found a solution to this. I've had a suggestion that calling
SetPowerRequirement may help but this does not seem to resolve the problem.

"Kevin FL" wrote:

> Roger - did you ever figure out anything on this?
>
> "Roger Vincent" wrote:
>
> > We found that on WM5 devices when we went into unattended mode we had to
> > issue a IOCTL_SERVICE_STOP / IOCTL_SERVICE_START to get GPS going again as it
> > stoped as soon as we went into unattended mode.
> >
> > On WM6 devices we get an error (device is an O2 XDA Orbit 2 aka HTC Polaris
> > aka HTC Touch Cruise). The last error value after the DeviceIoControl call
> > is 4319 'device not ready for use'.
> >
> > relevant .NET code snippet with PInvoke declarations as follows (this gets
> > called when we get notified that the device has entered the unattended power
> > state):
> >
> > [DllImport("coredll", SetLastError = true)]
> > static extern IntPtr CreateFile(String lpFileName,
> > [MarshalAs(UnmanagedType.U4)]FileAccess fileaccess,
> > [MarshalAs(UnmanagedType.U4)]FileShare fileshare, IntPtr
> > lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)]FileMode
> > creationdisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);
> >
> > [DllImport("coredll.dll", EntryPoint = "DeviceIoControl",
> > SetLastError = true)]
> > internal static extern int DeviceIoControlCE(
> > IntPtr hDevice,
> > uint dwIoControlCode,
> > IntPtr lpInBuffer,
> > int nInBufferSize,
> > IntPtr lpOutBuffer,
> > int nOutBufferSize,
> > ref int lpBytesReturned,
> > IntPtr lpOverlapped);
> >
> > [DllImport("coredll", SetLastError = false)]
> > static extern ulong GetLastError();
> >
> >
> > [DllImport("coredll.dll", SetLastError = true, CallingConvention =
> > CallingConvention.Winapi, CharSet = CharSet.Auto)]
> > [return: MarshalAs(UnmanagedType.Bool)]
> > public static extern bool CloseHandle(IntPtr hObject);
> >
> > public const uint IOCTL_SERVICE_START = 0x41000004;
> > public const uint IOCTL_SERVICE_STOP = 0x41000008;
> > public const uint IOCTL_SERVICE_REFRESH = 0x4100000C;
> > public const uint IOCTL_SERVICE_STATUS = 0x41000020;
> >
> > IntPtr deviceHandle = CreateFile("GPD0:", FileAccess.Read,
> > FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
> > int numBytesReturned = 0;
> > int result = 0;
> > int lastError = 0;
> > result = DeviceIoControlCE(deviceHandle, IOCTL_SERVICE_STOP,
> > IntPtr.Zero, 0, IntPtr.Zero, 0, ref numBytesReturned,
> > IntPtr.Zero);
> > if(result==0)
> > {
> > lastError = Marshal.GetLastWin32Error();
> > }
> > Thread.Sleep(5000);
> > result = DeviceIoControlCE(deviceHandle, IOCTL_SERVICE_START,
> > IntPtr.Zero, 0, IntPtr.Zero, 0, ref numBytesReturned,
> > IntPtr.Zero);
> > if (result == 0)
> > {
> > lastError = Marshal.GetLastWin32Error();
> > }
> >
> > We've also tried a call to SetPowerRequirement on GPD0: with
> > DevicePowerState DO prior to the CreateFile on GPD0: and that seems to have
> > the effect of changing the Win32 error code to 21 "The device is not ready.",
> > rather than 4319 "The device is not ready for use. "
> >
> > Any thoughts, suggestions, or especially fixes are welcome.