Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DWORD Time Puzzle

DWORD Time Puzzle

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelpc++databasewindows-admin
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    phil2415
    wrote on last edited by
    #1

    I know this isn't strictly a C++ problem but the application in question is written in C++ and this seems to be as good a place as any for some genius to come across this and answer it! OK, I have this puzzle that's been driving me crazy for over a week. Perhaps if I explain it to you someone can help me to crack it! I'm trying to replicated the behaviour of some software. It's a digital signage system and consists of a server application running, at the moment, on my PC, and a client which is a giant LCD screen with a built-in PC running Windows XP Embedded. In case anyone's familiar with it the sofware is MagicInfo by Samsung. The server application has the option to create an alert ticker message. It can be formatted, colours selected, etc. And when it's ready you hit the 'Send' button in the server console and instantly the message appears on the remote client screen. It'll keep running for the length of time I specified in the message setup or I can stop it by pressing the 'Stop' button in the server console. I've determined that the message itself and its formatting is contained in a simple XML file, which I'll paste below. Every time I update the message in the server the XML file on the client is updated. So, it's simple for me to come up with my own way to change the message. The hard part is how to trigger the display of the message. Remember, it can't be scheduled, it only appears when that 'Send' button is pressed. I have searched high and low on the client for SOMEWHERE that might store the on/off flag, or SOME indication of what changes when the message is activated. Getting in a bit over my head I've used network sniffer programs to examine the data packets sent between the server and the client when the message is activated and, sure enough, I can see the text of the updated message being sent. The client is permanently running a little application called XL_TICKER which seems to just sit there and wait for these packets from the server. However, attempting to replicate the packets manually with my limited knowledge has thus far failed to trigger the message on the client. So here's the puzzle. The ONLY thing that appears to change on the client each time I trigger the message (other than the XML file itself) is an entry in the Windows Registry, in a node containing various details about MagicInfo. There are two keys, called TickerStartTimeHigh and TickerStartTimeLow. These are DWORD values. The latter, TickerStartTimeLow, changes every time I trigger the ticker

    S 1 Reply Last reply
    0
    • P phil2415

      I know this isn't strictly a C++ problem but the application in question is written in C++ and this seems to be as good a place as any for some genius to come across this and answer it! OK, I have this puzzle that's been driving me crazy for over a week. Perhaps if I explain it to you someone can help me to crack it! I'm trying to replicated the behaviour of some software. It's a digital signage system and consists of a server application running, at the moment, on my PC, and a client which is a giant LCD screen with a built-in PC running Windows XP Embedded. In case anyone's familiar with it the sofware is MagicInfo by Samsung. The server application has the option to create an alert ticker message. It can be formatted, colours selected, etc. And when it's ready you hit the 'Send' button in the server console and instantly the message appears on the remote client screen. It'll keep running for the length of time I specified in the message setup or I can stop it by pressing the 'Stop' button in the server console. I've determined that the message itself and its formatting is contained in a simple XML file, which I'll paste below. Every time I update the message in the server the XML file on the client is updated. So, it's simple for me to come up with my own way to change the message. The hard part is how to trigger the display of the message. Remember, it can't be scheduled, it only appears when that 'Send' button is pressed. I have searched high and low on the client for SOMEWHERE that might store the on/off flag, or SOME indication of what changes when the message is activated. Getting in a bit over my head I've used network sniffer programs to examine the data packets sent between the server and the client when the message is activated and, sure enough, I can see the text of the updated message being sent. The client is permanently running a little application called XL_TICKER which seems to just sit there and wait for these packets from the server. However, attempting to replicate the packets manually with my limited knowledge has thus far failed to trigger the message on the client. So here's the puzzle. The ONLY thing that appears to change on the client each time I trigger the message (other than the XML file itself) is an entry in the Windows Registry, in a node containing various details about MagicInfo. There are two keys, called TickerStartTimeHigh and TickerStartTimeLow. These are DWORD values. The latter, TickerStartTimeLow, changes every time I trigger the ticker

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      The time is a FILETIME[^]. In fact, here's a little program that confirms that by using one of the times you give in your link, assigning it to a FILETIME and converting that to a SYSTEMTIME and writing out the time parts.

      #include <Windows.h>
      #include <iostream>

      int main()
      {
      SYSTEMTIME st;
      FILETIME ft;
      ft.dwLowDateTime = 2960830672;
      ft.dwHighDateTime = 30031143;
      FileTimeToSystemTime(&ft, &st);

      std::cout << st.wYear << std::endl;
      std::cout << st.wMonth << std::endl;
      std::cout << st.wDay << std::endl;
      std::cout << st.wHour << std::endl;
      std::cout << st.wMinute << std::endl;
      std::cout << st.wSecond << std::endl;
      }

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      P 1 Reply Last reply
      0
      • S Stuart Dootson

        The time is a FILETIME[^]. In fact, here's a little program that confirms that by using one of the times you give in your link, assigning it to a FILETIME and converting that to a SYSTEMTIME and writing out the time parts.

        #include <Windows.h>
        #include <iostream>

        int main()
        {
        SYSTEMTIME st;
        FILETIME ft;
        ft.dwLowDateTime = 2960830672;
        ft.dwHighDateTime = 30031143;
        FileTimeToSystemTime(&ft, &st);

        std::cout << st.wYear << std::endl;
        std::cout << st.wMonth << std::endl;
        std::cout << st.wDay << std::endl;
        std::cout << st.wHour << std::endl;
        std::cout << st.wMinute << std::endl;
        std::cout << st.wSecond << std::endl;
        }

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        P Offline
        P Offline
        phil2415
        wrote on last edited by
        #3

        Thanks Stuart, I'm so grateful that you were able to crack that one! Your code looks tantalisingly simple, but unfortunately I don't know C(++) at all and don't have anything to compile it with. I know VB.NET, though, and in fact that's what I'm using to write the program I'm hoping to incorporate this into. I've spent most of today Googling FileTime and SystemTime, creating my own structures in VB.NET and trying to achieve the feat of extracting the parts of the date as you have, but so far without success. At the moment it's returning a year of "67137" and a month of "65537", which seem completely meaningless to me and suggest that I've totally misunderstood what I'm doing and have just got lucky and managed to compile some code which will actually run, however pointless! I don't suppose you know how to achieve what your code does in VB.NET, do you?

        S 1 Reply Last reply
        0
        • P phil2415

          Thanks Stuart, I'm so grateful that you were able to crack that one! Your code looks tantalisingly simple, but unfortunately I don't know C(++) at all and don't have anything to compile it with. I know VB.NET, though, and in fact that's what I'm using to write the program I'm hoping to incorporate this into. I've spent most of today Googling FileTime and SystemTime, creating my own structures in VB.NET and trying to achieve the feat of extracting the parts of the date as you have, but so far without success. At the moment it's returning a year of "67137" and a month of "65537", which seem completely meaningless to me and suggest that I've totally misunderstood what I'm doing and have just got lucky and managed to compile some code which will actually run, however pointless! I don't suppose you know how to achieve what your code does in VB.NET, do you?

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          I'd start with Pinvoke.net[^], as that contains code snippets for declaring the necessary structures and function declarations. Once you've got those definitions in your code, the VB.NET code should follow logically form the C++ code - all I do is set the FILETIME structure to your time parts, call FileTimeToSystemTime and extract the date/time parts. This page[^] might also help.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          P 1 Reply Last reply
          0
          • S Stuart Dootson

            I'd start with Pinvoke.net[^], as that contains code snippets for declaring the necessary structures and function declarations. Once you've got those definitions in your code, the VB.NET code should follow logically form the C++ code - all I do is set the FILETIME structure to your time parts, call FileTimeToSystemTime and extract the date/time parts. This page[^] might also help.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            P Offline
            P Offline
            phil2415
            wrote on last edited by
            #5

            I've already been on Pinvoke.net and it seems that I have my structures and functions declared correctly. At the moment, using the same figures you plugged into your C code, I'm getting a year of "67137", a month of "65537" and a day of "5439544", without going into the hours, etc. Am I completely on the wrong track or are these numbers correct and just in need of some kind of further conversion to a date I an actually understand?

            S 1 Reply Last reply
            0
            • P phil2415

              I've already been on Pinvoke.net and it seems that I have my structures and functions declared correctly. At the moment, using the same figures you plugged into your C code, I'm getting a year of "67137", a month of "65537" and a day of "5439544", without going into the hours, etc. Am I completely on the wrong track or are these numbers correct and just in need of some kind of further conversion to a date I an actually understand?

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Imports System
              Imports System.Runtime.InteropServices

              Module Module1

              <StructLayout(LayoutKind.Sequential)> \_
              Public Structure FILETIME
                  Public dwLowDateTime As UInteger
                  Public dwHighDateTime As UInteger
              
                  Public ReadOnly Property Value() As ULong
                      Get
                          Return CType(dwHighDateTime << 32, ULong) + dwLowDateTime
                      End Get
                  End Property
              End Structure
              
              <StructLayout(LayoutKind.Sequential)> \_
              Public Structure SYSTEMTIME
                  <MarshalAs(UnmanagedType.U2)> Public Year As Short
                  <MarshalAs(UnmanagedType.U2)> Public Month As Short
                  <MarshalAs(UnmanagedType.U2)> Public DayOfWeek As Short
                  <MarshalAs(UnmanagedType.U2)> Public Day As Short
                  <MarshalAs(UnmanagedType.U2)> Public Hour As Short
                  <MarshalAs(UnmanagedType.U2)> Public Minute As Short
                  <MarshalAs(UnmanagedType.U2)> Public Second As Short
                  <MarshalAs(UnmanagedType.U2)> Public Milliseconds As Short
              End Structure
              
              <DllImport( \_
                         "kernel32.dll", \_
                         CharSet:=CharSet.Auto, \_
                         SetLastError:=True)> \_
                     Public Function FileTimeToSystemTime( \_
                                          <\[In\]()> ByRef lpFileTime As FILETIME, \_
                                          <Out()> ByRef lpSystemTime As SYSTEMTIME) \_
                                 As Boolean
              End Function
              
              Sub Main()
                  Dim st As SYSTEMTIME
                  Dim ft As FILETIME
              
                  ft.dwLowDateTime = 2960830672
                  ft.dwHighDateTime = 30031143
                  FileTimeToSystemTime(ft, st)
              
                  System.Console.WriteLine(st.Year)
                  System.Console.WriteLine(st.Month)
                  System.Console.WriteLine(st.Day)
                  System.Console.WriteLine(st.Hour)
                  System.Console.WriteLine(st.Minute)
                  System.Console.WriteLine(st.Second)
              End Sub
              

              End Module

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              P 1 Reply Last reply
              0
              • S Stuart Dootson

                Imports System
                Imports System.Runtime.InteropServices

                Module Module1

                <StructLayout(LayoutKind.Sequential)> \_
                Public Structure FILETIME
                    Public dwLowDateTime As UInteger
                    Public dwHighDateTime As UInteger
                
                    Public ReadOnly Property Value() As ULong
                        Get
                            Return CType(dwHighDateTime << 32, ULong) + dwLowDateTime
                        End Get
                    End Property
                End Structure
                
                <StructLayout(LayoutKind.Sequential)> \_
                Public Structure SYSTEMTIME
                    <MarshalAs(UnmanagedType.U2)> Public Year As Short
                    <MarshalAs(UnmanagedType.U2)> Public Month As Short
                    <MarshalAs(UnmanagedType.U2)> Public DayOfWeek As Short
                    <MarshalAs(UnmanagedType.U2)> Public Day As Short
                    <MarshalAs(UnmanagedType.U2)> Public Hour As Short
                    <MarshalAs(UnmanagedType.U2)> Public Minute As Short
                    <MarshalAs(UnmanagedType.U2)> Public Second As Short
                    <MarshalAs(UnmanagedType.U2)> Public Milliseconds As Short
                End Structure
                
                <DllImport( \_
                           "kernel32.dll", \_
                           CharSet:=CharSet.Auto, \_
                           SetLastError:=True)> \_
                       Public Function FileTimeToSystemTime( \_
                                            <\[In\]()> ByRef lpFileTime As FILETIME, \_
                                            <Out()> ByRef lpSystemTime As SYSTEMTIME) \_
                                   As Boolean
                End Function
                
                Sub Main()
                    Dim st As SYSTEMTIME
                    Dim ft As FILETIME
                
                    ft.dwLowDateTime = 2960830672
                    ft.dwHighDateTime = 30031143
                    FileTimeToSystemTime(ft, st)
                
                    System.Console.WriteLine(st.Year)
                    System.Console.WriteLine(st.Month)
                    System.Console.WriteLine(st.Day)
                    System.Console.WriteLine(st.Hour)
                    System.Console.WriteLine(st.Minute)
                    System.Console.WriteLine(st.Second)
                End Sub
                

                End Module

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                P Offline
                P Offline
                phil2415
                wrote on last edited by
                #7

                That is fantastic, thank you so much for taking the time. Your code worked perfectly for me and I've been able to extrapolate from that how to convert in the other direction too. I was very close to the code you've written, I'm not exactly sure where I was going wrong, but I don't care any more! Thanks again.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups