GetDeviceVersion on Mobile 2005 Device

Last post 10-31-2007 3:52 by Anonymous. 14 replies.
Page 1 of 1 (15 items)
Sort Posts: Previous Next
  • 11-03-2005 14:02

    GetDeviceVersion on Mobile 2005 Device

    I am currently testing our current application for issues with Windows Mobile 2005, and there appears to be an issue with the GetDeviceVersion function in Desktop.Communication.Rapi.

    My code goes something like this:
    m_Rapi = New Desktop.Communication.Rapi
    ..
    ..
    m_rapi.GetDeviceSytemPowerStatus
    m_Rapi.GetDeviceMemoryStatus
    m_Rapi.getDeviceVersion
    ..

    After hitting the GetDeviceVersion call when attached to a WM2005 device I check the value of m_Rapi and it is nothing...

    Has anyone come across this, and know a quick-fix for it?

    thanks in advance

    Jim P.
  • 11-03-2005 14:44 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    I'm developing for Windows Mobile 5.0 and ran across this also.

    There are some problems with Rapi.GetDeviceVersion() that prevent it from working. I don't know if there is a workaround other than to get the source code and fix it there.

    (1) The pinvoke code is wrong, it uses

    CeGetVersionEx(out verinfo)

    when it should be doing

    CeGetVersionEx(ref verinfo)

    Since we're setting the size of the structure and passing it down, this has to use a ref.


    (2) For some reason, using the OSVERSIONINFO (if I don't include the szCSDVersion, my app crashes without any exceptions being thrown). So you will have to use the CEOSVERSIONINFO that includes the szCSDVersion.

    Thus the pinvoke code should look like this

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    public struct CEOSVERSIONINFO
    {
    internal int dwOSVersionInfoSize;
    public int dwMajorVersion;
    public int dwMinorVersion;
    public int dwBuildNumber;
    public PlatformType dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
    public string szCSDVersion;
    }

    [DllImport("rapi.dll", CharSet=CharSet.Unicode, SetLastError=true)]
    internal static extern int CeGetVersionEx(ref CEOSVERSION lpVersionInformation);


    --Kenn
  • 11-04-2005 6:00 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Hi Kenn

    I too have encountered these problems and have made the changes you recommended above but cannot get them to work (the code compiles OK but it just falls over with no exceptions) [xx(]

    I know this is cheeky, but could I perhaps trouble you to post a fixed version of this dll or to email me a copy?

    Many thanks for your time [:)]
    Gee
  • 11-04-2005 6:21 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Hi Kenn

    Using the original DLL, I discovered that the original function will work without bombing your application if you connect to the device BEFORE trying to ascertain it's OS Info...

    Eg:

    RAPI x = new RAPI();
    if(x.DevicePresent)
    {
    x.Connect();
    if(x.Connected)
    {
    x.GetDeviceVersion(out y);
    MessageBox.Show(""+y.dwPlatformId.ToString());
    }
    }
    else
    {
    MessageBox.Show("No device present!");
    }

    Well it worked for me anyway ;)
  • 11-04-2005 13:52 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Hmm.. that's very interesting. I was already connected so that shouldn't be a problem.

    Are you running Windows Mobile 2005? The current code (the download, not the Source Vault version) makes no sense. We need to set the size of the OSVERSIONINFO struct, but since we're using an out parameter the size should never get passed down (unless they didn't optimize the out parameter case).

  • 11-10-2005 1:17 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Hi Kenn

    Now, bog standard 2003!

    Gee
  • 11-10-2005 6:58 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    quote:
    Originally posted by Kenn

    I'm developing for Windows Mobile 5.0 and ran across this also.

    There are some problems with Rapi.GetDeviceVersion() that prevent it from working. I don't know if there is a workaround other than to get the source code and fix it there.

    (1) The pinvoke code is wrong, it uses

    CeGetVersionEx(out verinfo)

    when it should be doing

    CeGetVersionEx(ref verinfo)

    Since we're setting the size of the structure and passing it down, this has to use a ref.


    (2) For some reason, using the OSVERSIONINFO (if I don't include the szCSDVersion, my app crashes without any exceptions being thrown). So you will have to use the CEOSVERSIONINFO that includes the szCSDVersion.

    Thus the pinvoke code should look like this

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    public struct CEOSVERSIONINFO
    {
    internal int dwOSVersionInfoSize;
    public int dwMajorVersion;
    public int dwMinorVersion;
    public int dwBuildNumber;
    public PlatformType dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
    public string szCSDVersion;
    }

    [DllImport("rapi.dll", CharSet=CharSet.Unicode, SetLastError=true)]
    internal static extern int CeGetVersionEx(ref CEOSVERSION lpVersionInformation);


    --Kenn

    Thanks Kenn. I had the same problem with WM 5.0 and that fix works perfectly.
  • 11-16-2005 13:44 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Changed to CEOsversionInfo and it works well now. thanks Kenn!
  • 11-18-2005 5:44 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Could someone post a fixed version for me please as I am having no joy with these changes!!
    Thanks ;)

    Gee
  • 11-23-2005 9:31 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    I am having similar problems. It seems to me that the function call works as long as you have ActiveSync 3.7 or 3.8 installed, but fails when I try to use my new Dell Axim with Windows Mobile 5.0 which seems to require ActiveSync 4.0.
  • 01-17-2006 16:43 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    *Please* (grovelling now!!!) can someone foward me a fixed version so I can see exactly where I am going wrong making these changes?

    tech [AT] factorymaster [.] CO [dot] UK

    Thank you
  • 01-22-2007 1:38 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    Hi Gee,

    I came across the same problem this evening and must confess that I freaked out because I have a deadline in 48 hours to deliver my app to a client with four WM 5.0 devices. But thanks to Kenn the problem is now solved! There is a minor typo in his solution but other than that it's perfect. Here's a larger portion of code for you. I'll also follow-up with an e-mail to you because I know exactly where you're at frustration-wise!

    using System;
    using System.IO;
    using OpenNETCF.Desktop.Communication;
    using System.Runtime.InteropServices;

    namespace DataTransfer
    {
    // Required to correct a bug with OSVERSIONINO when connecting to a WM 5.0 device
    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    public struct CEOSVERSIONINFO
    {
    internal int dwOSVersionInfoSize;
    public int dwMajorVersion;
    public int dwMinorVersion;
    public int dwBuildNumber;
    public PlatformType dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
    public string szCSDVersion;
    }


    public class RapiTools
    {
    // Required to correct a bug with OSVERSIONINO when connecting to a WM 5.0 device
    [DllImport("rapi.dll", CharSet=CharSet.Unicode, SetLastError=true)]
    internal static extern int CeGetVersionEx(ref CEOSVERSIONINFO lpVersionInformation);


    public static CEOSVERSIONINFO GetOSInfo(RAPI rapi)
    {
    CEOSVERSIONINFO verInfo = new CEOSVERSIONINFO();
    CeGetVersionEx(ref verInfo);
    return verInfo;
    }
    }
    }




    Robert Werner
    Vancouver, BC
    www.mwtech.com
  • 01-22-2007 7:18 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 2,149

    Re: GetDeviceVersion on Mobile 2005 Device

    The layout bug was already fixed in Vault. The ref/out paramter issue was still there and I've fixed that. Your solution works, but it breaks the interface so any existing code using it will no longer work. Below is an alternate that uses the same interface. This is also in Vault and I'll try to publish a new compiled drop today.


    public void GetDeviceVersion(out OSVERSIONINFO VersionInfo)
    {
    CheckConnection();
    OSVERSIONINFO vi = new OSVERSIONINFO();
    vi.dwOSVersionInfoSize = Marshal.SizeOf(vi);

    bool b;

    VersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFO));

    b = CeGetVersionEx(out vi);

    if(!b)
    {
    throw new RAPIException("Error retrieving version information.", Marshal.GetLastWin32Error());
    }

    VersionInfo = vi;
    }

  • 01-22-2007 7:30 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 2,149

    Re: GetDeviceVersion on Mobile 2005 Device

    Also note that the proposed fixed are incorrect in the OSVERSIONINFO declaration. szCSDVersion is defined in C as WCHAR szCSDVersion[ 128 ] which is 256 bytes, not 128.
  • 10-31-2007 3:52 In reply to

    Re: GetDeviceVersion on Mobile 2005 Device

    hi ctacke.
    Are you suggesting that the line:

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string szCSDVersion;

    Should be:
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
    public string szCSDVersion;

    The documentation for the SizeConst parameter of the MarshalAs attribute states that it is the 'number of elements in the array, or the number of characters (not bytes) in a string to import'.

    I'm currently having some problems where leaving a device connected for a long time causes a crash and I'm wondering if the GetDeviceVersion call could be causing the issue. My current code has the SizeConst parameter set to 128.

    Thanks


Page 1 of 1 (15 items)