Prev: CProgressDlg
Next: ActiveX inside a CDHtmlDialog
From: Alexander Mair on 19 Oct 2006 07:31 Hello, I have ported a VS.NET 2003/MFC7 application to VS 2005/MFC8 and encountered a problem with COleDateTime::GetCurrentTime() which worked fine with MFC7. Sometimes I get an invalid COleDateTime object from GetCurrentTime() (m_status equals COleDateTime::invalid). I tracked the problem down to AtlConvertSystemTimeToVariantTime() which is called during conversion from SYSTEMTIME to double time representation. AtlConvertSystemTimeToVariantTime() calls SystemTimeToVariantTime() to convert from SYSTEMTIME to double. VariantTimeToSystemTime is used then to convert the result back to SYSTEMTIME. When this result is compared to the original SYSTEMTIME a difference is encountered. The difference is from a few seconds up to a few minutes. Where does the difference come from? Shouldn't GetCurrentTime() always return a valid COleDateTime object? Any idea? I am using MFC in Shared DLL, Multithreaded DLL, Debug Configuration; a few modules are CLR compiled so the result is a mixed mode EXE. Thanks, Alex
From: David Lowndes on 19 Oct 2006 15:25 >Sometimes I get an invalid COleDateTime object from GetCurrentTime() >(m_status equals COleDateTime::invalid). Alex, Do you have an example that illustrates how to reproduce the problem? Dave
From: Alexander Mair on 23 Oct 2006 03:38 "David Lowndes" <DavidL(a)example.invalid> wrote in message news:9cffj29pmu1jrjaa84boa1i2cs66qugup7(a)4ax.com... > >Sometimes I get an invalid COleDateTime object from GetCurrentTime() >>(m_status equals COleDateTime::invalid). > > Alex, > > Do you have an example that illustrates how to reproduce the problem? > > Dave Dave, I simply do the following: const COleDateTime dtNow = COleDateTime::GetCurrentTime(); if ( COleDateTime::valid != m_dtStatusSince.GetStatus() || m_dtStatusSince > dtNow ) return _T( "" ); dtNow.m_status equals COleDateTime::invalid after the call to GetCurrentTime() which causes an ASSERT when comparing m_dtStatusSince to dtNow. Alex
From: David Lowndes on 23 Oct 2006 04:08 >I simply do the following: > > const COleDateTime dtNow = COleDateTime::GetCurrentTime(); > if ( COleDateTime::valid != m_dtStatusSince.GetStatus() > || m_dtStatusSince > dtNow ) > return _T( "" ); > >dtNow.m_status equals COleDateTime::invalid after the call to >GetCurrentTime() which causes an ASSERT when comparing m_dtStatusSince to >dtNow. Alex, The following doesn't show up a problem for me: #include "stdafx.h" #include <ATLComTime.h> int _tmain(int argc, _TCHAR* argv[]) { const COleDateTime dtNow = COleDateTime::GetCurrentTime(); if ( dtNow.m_status == COleDateTime::invalid ) { return 1; } return 0; } Dave
From: Alexander Mair on 23 Oct 2006 10:04
> The following doesn't show up a problem for me: > > #include "stdafx.h" > #include <ATLComTime.h> > > int _tmain(int argc, _TCHAR* argv[]) > { > const COleDateTime dtNow = COleDateTime::GetCurrentTime(); > > if ( dtNow.m_status == COleDateTime::invalid ) > { > return 1; > } > > return 0; > } > > Dave Dave, I made some additional tests and found out that the problem seems to be related to Direct3D!? I use the DirectX 9.0 SDK (October 2005). As soon as I initialize Direct3D and create a Direct3D device the call to COleDateTime::GetCurrentTime() fails with m_status equal to COleDateTime::invalid. I can reproduce the problem using a simple dialog based MFC application project (Visual Studio 2005, Windows XP SP2): 1. Create a new 'MFC Application' project. 2. Modify the following settings in the MFC Application Wizard: Application Type = Dialog based Use Unicode libraries OFF 3. Add the following to "stdafx.h": #include <comdef.h> #include <d3d9.h> #include <D3dx9math.h> 4. Add the following code directly after the call to "CDialog::OnInitDialog();" in <class>::OnInitDialog(): _COM_SMARTPTR_TYPEDEF( IDirect3D9, __uuidof( IDirect3D9 )); _COM_SMARTPTR_TYPEDEF( IDirect3DDevice9, __uuidof( IDirect3DDevice9 )); IDirect3D9Ptr D3DPtr; IDirect3DDevice9Ptr D3DDevicePtr; try { D3DPtr.Attach( ::Direct3DCreate9( D3D_SDK_VERSION )); if ( NULL == D3DPtr ) _com_issue_error( E_FAIL ); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.hDeviceWindow = *this; d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; HRESULT hr = D3DPtr->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, *this, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &D3DDevicePtr ); if ( FAILED( hr )) _com_issue_error( hr ); const COleDateTime dtNow = COleDateTime::GetCurrentTime(); if ( COleDateTime::invalid == dtNow.GetStatus() ) AfxMessageBox( _T( "GetCurrentTime() returned an invalid COleDateTime!" )); } catch( _com_error & ) { AfxMessageBox( _T( "Direct3D initialization failed!" )); } 5. In the project properties add the directory "$(DXSDK_DIR)\Lib\x86" to "Linker - General - Additional Library Directories" and the libraries "d3d9.lib d3dx9.lib" to "Linker - Input - Additional Dependencies". Running the application displays a message box with "GetCurrentTime() returned an invalid COleDateTime.". Omitting the line HRESULT hr = D3DPtr->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, *this, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &D3DDevicePtr ); returns a valid COleDateTime() object. Thanks, Alex |