Q:
How to convert a FILETIME structure to a CComVariant object to be stored in any of the Inventor date-type Properties?
A:
If you have a FILETIME structure and want to store its contents into one of the date-type Properties for example "Creation Time" Property of the "Design Tracking Properties" PropertySet, a COleDateTime object has to be used as an intermediate object of conversion. One of the constructors of the ColeDateTime class can take a FILETIME structure pointer. With the COleDateTime object created, this can be assigned to a CComVariant object. The CComVariant object can then be passed to the Property->PutValue method.
HRESULT AddDateProp(
CComPtr<ApprenticeServerDocument>
pApprenticeServerDocument)
{
HRESULT hr;
// Get property sets
CComPtr<PropertySets> pPropSets;
hr = pApprenticeServerDocument->get_PropertySets(
&pPropSets);
if FAILED(hr)
return hr;
// Get "Design Tracking Properties" property set
CComPtr<PropertySet> pPropSet;
hr = pPropSets->get_Item(
CComVariant("Design Tracking Properties"),
&pPropSet);
if FAILED(hr)
return hr;
// Get "Creation Time" property
CComPtr<Property> pProp;
hr = pPropSet->get_Item(
CComVariant("Creation Time"), &pProp);
if FAILED(hr)
return hr;
// Creates FILETIME structure
FILETIME filetime;
filetime.dwHighDateTime = 200;
filetime.dwLowDateTime = 100;
// Create a COleDateTime object
// based on the FILETIME structure
COleDateTime newtime(filetime);
// Put the value in the date-type Property
hr = pProp->put_Value(CComVariant(newtime));
if FAILED(hr)
return hr;
// Save changes to the properties
hr = pPropSets->FlushToFile();
if FAILED(hr)
return hr;
// Close the Apprentice object
hr = pApprenticeServerDocument->Close();
if FAILED(hr)
return hr;
return hr;
}