System.TimeZone.CurrentTimeZone

I am writing an application for a Windows Mobile device using C# and .Net Compact framework. I need to obtain the system timezone or timezone that the user specifies in the Settings/Date and Time area. System.TimeZone is an abstract class and if I do try to call System.TimeZone.CurrentTimeZone I get a NotSupported exception. I have also tried p/invoking GetTimeZoneInformation() and also received a NotSupported exception. I went to pinvoke.net to see what methods are available under coredll.dll and GetTimeZoneInformation is not there, so I have no idea how I am to get the timezone.

Thanks

Harry



Answer this question

System.TimeZone.CurrentTimeZone

  • sorcer1

    Which version of NETCF v2 do you have Can you print out System.Environment.Version in your application

    Also, which OS version is on that Q



  • shaw79

    I have tried that, but I still get a NotSupportedException. I changed the DLLImport line from kernel32.dll to coredll.dll and also to cellcore.dll, but I just don't think the method is there. Is there any reason why System.TimeZone.CurrentTimeZone.StandardName does not work
  • Afzala

    I am using NETCF V2 on a Motorola Q device running windows mobile 5.0

    Harry


  • jnelsonjr

    The output from System.Environment.Version is 1.0.4292.0 Does this indicate that it is NETCF V1 I downloaded and installed NETCF V2 onto the device.

    The output from the System.Environemnt.OSVersion is "Microsoft Windows CE 5.1.195"

    Thanks

    Harry


  • cka11

    Yes, that's NETCF V1 and that's what I was suspecting. Does not matter if you have V2 installed or not - your application is created for V1 and runs against V1.

    You can either upgrade your project to V2 (look through VS 2005 menus) or change P/Invoke code as I’ve described above.



  • #pragma

    That worked. I really appreciate your help! When I was trying p/invoking the GetTimeZoneInformation() call , I did receive a NotSupported Exception. I did use the same structure, etc that was listed on pinvoke.net, but the MarhsallAs statements were not working and I could not compile with them. After upgrading the project, it now works. If I deploy this V2 application to a device running V1, will it work Or will all devices running a V2 application need to be upgraded to V2

    Also, any idea and how to send DTMF tones on a call that is currently taking place I have installed the OPENNETCF Tapilib.dll, but there is no lineGeneratedDigits() method or anything that I can find that is similar.

    Thank you for your help

    Harry


  • noel 55

    You can package it, but sure enough it won't work – different OS and different CPUs are major show stoppers.

    There’s a better way though: in the source code from pinvoke.net find "kernel32" and replace it with "coredll", now you should be all set. You can do that trick for pretty much any API which is common for both desktop and device.



  • Xiao Feng

    GetTimeZoneInformation() lives under kernel32.dll, but kernel32.dll is not on the mobile device. Can I simply package the desktop version of kernel32.dll into my CAB file I am trying to keep my distribution size as small as possible.

    Harry


  • Dave Waterworth

    NETCF V2 is required in order to run V2 applications, V1 naturally won't do. And you did not use the _same_ structure, you managed it in order to compile. You still can make it work on V1 if you un-wrap embedded strings and structures.

    As to your other question, you should start a new thread. Before you do that please search if there's an answer already as I remember something like this.



  • Billr17

    You should be able to P/Invoke GetTimeZoneInformation(). If you're on NETCF V2, use this declaration from pinvoke.net.

    If for some strange reason you're still on NETCF V1, you have to unwrap nested strings in the structure (and probably nested structure as well) as NETCF V1 does not support marshaling them.

    E.g. instead of this:

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string daylightName;

    use this:

    public char daylightName0;

    public char daylightName1;

    public char daylightName2;

    ...

    public char daylightName31;

    Combine these characters to string as needed.



  • David Botz

    System.TimeZone.CurrentTimeZone.StandardName works fine for me – I’ve just tried it on NETCF V2 and PPC 2003 emulator.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

     

    I would guess System.TimeZone.CurrentTimeZone.StandardName is not supported on NETCF V1.

     

    Which version of NETCF are you using Which device are you using

     

    If you’re on NETCF V1 you have to use P/Invoke and you have to unwrap nested strings and structures the way I’ve described above or you will get a NotSupportedException as marshaling of nested strings is not supported on NETCF V1.



  • System.TimeZone.CurrentTimeZone