From: Alexander Mair on
Because the problem seems to be not related to MFC but to DirectX, I posted
it to microsoft.public.directx.graphics.

Alex


"Alexander Mair" <alexander.mair(a)btec.at> wrote in message
news:OrCX5wq9GHA.4196(a)TK2MSFTNGP03.phx.gbl...
>> 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
>


From: David Lowndes on
Alex,

I don't have D3D9 SDK installed so I can't reproduce your situation,
however I have no reason to disbelieve it, so I suggest that you
submit a bug report (include the simplest example to reproduce the
problem) on VS2005 at:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

My initial though is that it may have something to do with D3D
altering the floating point processor settings - but it's a shot in
the dark!

Post a link back here to your bug report.

Dave
From: Alexander Mair on
> My initial though is that it may have something to do with D3D
> altering the floating point processor settings - but it's a shot in
> the dark!
>

You are right, it has to do with altering floating point processor settings.
Using the flag D3DCREATE_FPU_PRESERVE when creating the Direct3D device
solves the problem.

Thank you very much for your help,
Alex


From: David Lowndes on
>> My initial though is that it may have something to do with D3D
>> altering the floating point processor settings - but it's a shot in
>> the dark!
>
>You are right, it has to do with altering floating point processor settings.
>Using the flag D3DCREATE_FPU_PRESERVE when creating the Direct3D device
>solves the problem.

Ah, that's good - though a bit disconcerting that it should be a
problem at all.

Dave
From: David Lowndes on
>You are right, it has to do with altering floating point processor settings.
>Using the flag D3DCREATE_FPU_PRESERVE when creating the Direct3D device
>solves the problem.

Searching the newsgroups it appears that others have also suffered
from this problem :(

If you've not done so, I think it'd be worthwhile submitting a bug
report on it (and the solution) to ensure MS are aware of the problem
- and so they can come up with some solution in the future, even if
that's only documenting the fact that something as innocuous as
COleDateTime::GetCurrentTime() can fail because of the floating point
settings.

FWIW, I can now repro the problem with this simple test:

#include "stdafx.h"
#include <ATLComTime.h>
#include <float.h>

int _tmain(int argc, _TCHAR* argv[])
{
unsigned int cw;

_controlfp_s( &cw, _PC_24, _MCW_PC );

const COleDateTime dtNow = COleDateTime::GetCurrentTime();

if ( dtNow.m_status == COleDateTime::invalid )
{
return 1;
}

return 0;
}


Dave
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: CProgressDlg
Next: ActiveX inside a CDHtmlDialog