Convert Hexstring to date in VC++ 6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ezima Ugwu
    New Member
    • Dec 2011
    • 4

    Convert Hexstring to date in VC++ 6.0

    Hi,
    I have a date value that is converted to long in VB using
    CLng(Cdate(valu e) and the the long value is converted to a HexString which is then stored in the registry.

    I have a VC++ 6.0 application that reads this value from the registry and use the date but I am having problem converting the read Hexstring back the date value in my VC++ code.

    Say I start with CLng(CDate(02/01/2011)) and then convert this a "AF5B" (not the real value**) which is then stored in the registry.

    I wish to read "AF5B" in VC++ and be able to convert it back to 02/01/2011".

    Any ideas on how I can do this? Any help appreciated.

    Thanks,

    Ezima Ugwu.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Can yu not just convert the hex string to an int and create another CDate?

    Comment

    • Ezima Ugwu
      New Member
      • Dec 2011
      • 4

      #3
      Hi,

      I am reading the hexstring from VC++ and the only methods I know such as time_t, CTime, COleDateTime etc are not generating the correct date. I cannot do a direct CDate cast in VC++.

      Thanks,

      Ezima Ugwu

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You say you start with this:
        Code:
        Say I start with CLng(CDate(02/01/2011))
        is this not part of your C++ Program? Because you are creating a CDate as an argument to CLng. This is not a cast but is a constructor call. Other constructors of CDate take an int as an argument.

        You can cnvert your hex string to an int and then create a CDate object using the string. You should be able to get your date from this object.

        Comment

        • Ezima Ugwu
          New Member
          • Dec 2011
          • 4

          #5
          Hi all,
          I have now figured this out. VB uses Ole Automation so the correct C++ datetime format is COleDateTime. I convert the long value from VB to a double and assign it to a COleDateTime variable and the rest is done using COleDateTime class members.

          Thanks to all those that replied.

          Ezima Ugwu.

          Comment

          Working...