Game Development Community

CheckDXVersion() relies on Unicode

by Stefan Lundmark · in Torque Game Engine Advanced · 08/06/2007 (4:07 pm) · 5 replies

CheckDXVersion () among two other functions relies on Unicode strings so it can not be compiled with it off. Might as well make Unicode mandatory that way.

If you want to use the Multi-Byte set in favour of Unicode, I'm including a hack to do it below. Please note that it is a hack and it doesn't work with Unicode.

ScreenshotD3D.cpp @ Line 154
Change:
GFXD3DX.D3DXSaveSurfaceToFileW( dT( "testScreen.png" ), D3DXIFF_PNG, surface, NULL, NULL );

Into:
GFXD3DX.D3DXSaveSurfaceToFile( "testScreen.png", D3DXIFF_PNG, surface, NULL, NULL );

Inside gfxD3DDevice.cpp. Replace GFXD3DDevice::getDXVersion() with this:
char * GFXD3DDevice::getDXVersion()
{
#ifdef UNICODE
   UTF16 dxVersionLetter;
#else
   char dxVersionLetter;
#endif

   static char dxVersionString[32];

   DWORD dxVersion, dxRevision;

   NVDXDiagWrapper::DXDiagNVUtil * dxDiag = new NVDXDiagWrapper::DXDiagNVUtil();
   dxDiag->InitIDxDiagContainer();
   dxDiag->GetDirectXVersion( &dxVersion, &dxRevision, &dxVersionLetter );
   dxDiag->FreeIDxDiagContainer();
   delete dxDiag;

#ifdef UNICODE
   convertUTF16toUTF8( &dxVersionLetter, (UTF8 *)&versionLetter, sizeof(versionLetter) );
#endif

   dSprintf( dxVersionString, sizeof(dxVersionString), "%d.%d%c", dxVersion, dxRevision, dxVersionLetter );

   return dxVersionString;
}

Finally, add this include in dxVersionChecker.cpp:
#include "platformWin32/platformWin32.h"

And replace checkDXVersion() with this:
bool checkDXVersion()
{
   // Init the strings and such
   initVersionStrings( D3DXDLL_VER );

   DWORD dwVersion = 0;

   // call dx version check supplied by the SDK sample
   HRESULT hr = GetDXVersion( &dwVersion, 0, 0 );

   // If there is a dx version, check the version against the desired DLL 
   // version and deal with it.
   if( SUCCEEDED( hr ) )
   {
      char cPath[_MAX_PATH] = { 0 }, cFilename[_MAX_PATH] = { 0 };

      GetWindowsDirectory( cPath, _MAX_PATH );

      dSprintf( cFilename, _MAX_PATH, "%s\system32\d3dx9_%d.dll", cPath, gD3DXDLLVersion );

      HANDLE hFile = CreateFile( cFilename, GENERIC_READ,
         FILE_SHARE_READ, 0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0 );

      CloseHandle( hFile );

      if( hFile == INVALID_HANDLE_VALUE )
      {
         OutputDebugString( "DX Version Checker: Requested D3DX DLL version not found!\n" );
         dwVersion = 0;
      }
   }

   // Check version
   if( dwVersion < gDXVersion )
   {
      char promptMessage[512];
      dSprintf( promptMessage, sizeof( promptMessage ) / sizeof( WCHAR ), 
         "This application requires the %s or later.\n Press OK to install "
         "%s, or Cancel to exit.", gDXVersionString, gDXVersionString );

      long dw = MessageBox( 0, TEXT(promptMessage), "DirectX Version Checker", MB_OKCANCEL | MB_ICONEXCLAMATION );

      // If they cancel, just return false and let the init() deal with it
      if( dw == IDCANCEL )
         return false;
   }

   return true;
}

#1
12/23/2007 (11:50 pm)
What advantage does this provide?
#2
01/01/2008 (9:12 am)
Hi Ron.

Quote:
CheckDXVersion () among two other functions relies on Unicode strings so it can not be compiled with it off.
#3
01/01/2008 (9:23 am)
It makes not sense to do so anyway.
Any OS that has the needed DX version has Unicode as well. Non Unicode Windows OS Versions do not have the current DX releases as Win98 ME were abandoned last year.

Any specific reason you try to get rid of unicode?
#4
01/01/2008 (10:46 am)
Nowhere did I state that I wanted to get rid of Unicode.

One's opinion on Unicode, be it yours or mine, is irrelevant. There's an option to disable Unicode via the preprocessor, and if you chose to do so it won't compile. It's not working as intended and no longer an option.
#5
01/01/2008 (10:51 am)
So the clean thing would be to remove the option as there is no non-unicode Windows version anymore and it is therefor a not any further needed option for TGEA. (Its one of those things that came over from TGE and TGE, unlike TGEA runs on the abandoned Windows platforms. TGEA although will not, even if you compile it non-unicode)