Search code examples
datevisual-c++comatlidl

How to pass time_t or simply its date information over COM


I have a Visual C++ ATL project which exposes a COM interface.

From my interface, I am calling into FlexNet Publisher libraries. I need to return back a date from these libraries, which expose a time_t object I can fetch (yes, I know their libraries are susceptible to the 2038 bug on 32-bit systems).

My IDL file has a method on it which needs to return this date.

Given that I can fetch time_t, how do I pass its date information across the COM interface boundary to a client application consuming my COM object? Should I just cast time_t as __int64 and define it as __int64 in my IDL? What's correct here? What's the standard way?


Solution

  • I'd recommend using the oleautomation compliant DATE type.

    To convert your existing time_t type, use the COleDateTime class, which is provided by ATL. One of its constructors accepts a time_t value and parses it to its equivalent DATE value.