News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

DirectX

Started by Cor, November 17, 2004, 01:36:37 AM

Previous topic - Next topic

Cor

How to check directx version from source.

gr.

cor
Cor de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
http://www.chordplanet.com

kevin


tomazmb

Hello,

From all the forums here where I posted, I didn't make a post where I really belong -> in the Beginners section. My mistake. :)

Back to my question.

Cor wrote:

QuoteHow to check directx version from source.

Kevin answered:

Quoteyou can't

Did I understand correctly. Cor wanted to know how can we in Play Basic to find out if the user have the proper DirectX version installed (in the way to find out what version of DirectX is installed) ? And Kevin answered you can't ? If so, why ?

Have a nice day,

Tomaz
My computer specification:

AMD Athlon 64 2800+
MB ASUS K8V Socket 754 VIA K8T800
SB Audigy 2
3 GB RAM DDR 400 MHz PQI
AGP NVIDIA GeForce 7600GT 256 MB-Club 3D
Windows XP Pro SP2
DirectX 9.0c

kevin

Well, it's a bit of a catch 22.  as In order to run your program, the user must have Dx3 at least .  If you don't, it won't run to begin with.    That's why there's no command inside the language.

tomazmb

Hello,

I ask this because I've played games which has this version check at the beginning. And if the system doesn't have a proper DirectX version, it can be installed together with the game installation. As I understand it, at first some kind of windows installation programs start and if the requirements are met, then the game starts.

Have a nice day,

Tomaz
My computer specification:

AMD Athlon 64 2800+
MB ASUS K8V Socket 754 VIA K8T800
SB Audigy 2
3 GB RAM DDR 400 MHz PQI
AGP NVIDIA GeForce 7600GT 256 MB-Club 3D
Windows XP Pro SP2
DirectX 9.0c

Jeku

You'd most likely need to create a loader in a different language (i.e. C++/C#) that detects the DX version then loads the game.  It could be completely transparent as long as you place the loader shortcut in the start menu.
**
Automaton Games - Home of WordTrix 2.0, WordZap, and GameBasic
Jeku's Music - Easy listening electronic...
**

tomazmb

#6
Hello Kevin,

I found somewhere on the net:

DirectX detection from Microsoft

Is this possible to do it in Playbasic or not ? In green is C code.

Have a nice day,

Tomaz


[color=green]DIRECTDRAWCREATE     DirectDrawCreate   = NULL;
   DIRECTDRAWCREATEEX   DirectDrawCreateEx = NULL;
   DIRECTINPUTCREATE    DirectInputCreate  = NULL;
   HINSTANCE            hDDrawDLL          = NULL;
   HINSTANCE            hDInputDLL         = NULL;
   HINSTANCE            hD3D8DLL           = NULL;
   HINSTANCE            hDPNHPASTDLL       = NULL;
   LPDIRECTDRAW         pDDraw             = NULL;
   LPDIRECTDRAW2        pDDraw2            = NULL;
   LPDIRECTDRAWSURFACE  pSurf              = NULL;
   LPDIRECTDRAWSURFACE3 pSurf3             = NULL;
   LPDIRECTDRAWSURFACE4 pSurf4             = NULL;
   DWORD                dwDXVersion        = 0;
   HRESULT              hr;

   // First see if DDRAW.DLL even exists.
   hDDrawDLL = LoadLibrary( "DDRAW.DLL" );
   if( hDDrawDLL == NULL )
   {
       dwDXVersion = 0;
       OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
       return dwDXVersion;
   }

   // See if we can create the DirectDraw object.
   DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( hDDrawDLL, "DirectDrawCreate" );
   if( DirectDrawCreate == NULL )
   {
       dwDXVersion = 0;
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't GetProcAddress DirectDrawCreate\r\n" );
       return dwDXVersion;
   }

   hr = DirectDrawCreate( NULL, &pDDraw, NULL );
   if( FAILED(hr) )
   {
       dwDXVersion = 0;
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't create DDraw\r\n" );
       return dwDXVersion;
   }

   // So DirectDraw exists.  We are at least DX1.
   dwDXVersion = 0x100;

   // Let's see if IID_IDirectDraw2 exists.
   hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
   if( FAILED(hr) )
   {
       // No IDirectDraw2 exists... must be DX1
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't QI DDraw2\r\n" );
       return dwDXVersion;
   }

   // IDirectDraw2 exists. We must be at least DX2
   pDDraw2->Release();
   dwDXVersion = 0x200;


  //-------------------------------------------------------------------------
   // DirectX 3.0 Checks
  //-------------------------------------------------------------------------

   // DirectInput was added for DX3
   hDInputDLL = LoadLibrary( "DINPUT.DLL" );
   if( hDInputDLL == NULL )
   {
       // No DInput... must not be DX3
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
       return dwDXVersion;
   }

   DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( hDInputDLL,
                                                       "DirectInputCreateA" );
   if( DirectInputCreate == NULL )
   {
       // No DInput... must be DX2
       FreeLibrary( hDInputDLL );
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
       return dwDXVersion;
   }

   // DirectInputCreate exists. We are at least DX3
   dwDXVersion = 0x300;
   FreeLibrary( hDInputDLL );

   // Can do checks for 3a vs 3b here


  //-------------------------------------------------------------------------
   // DirectX 5.0 Checks
  //-------------------------------------------------------------------------

   // We can tell if DX5 is present by checking for the existence of
   // IDirectDrawSurface3. First, we need a surface to QI off of.
   DDSURFACEDESC ddsd;
   ZeroMemory( &ddsd, sizeof(ddsd) );
   ddsd.dwSize         = sizeof(ddsd);
   ddsd.dwFlags        = DDSD_CAPS;
   ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

   hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
   if( FAILED(hr) )
   {
       // Failure. This means DDraw isn't properly installed.
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       dwDXVersion = 0;
       OutputDebugString( "Couldn't Set coop level\r\n" );
       return dwDXVersion;
   }

   hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
   if( FAILED(hr) )
   {
       // Failure. This means DDraw isn't properly installed.
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       dwDXVersion = 0;
       OutputDebugString( "Couldn't CreateSurface\r\n" );
       return dwDXVersion;
   }

   // Query for the IDirectDrawSurface3 interface
   if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
                                      (VOID**)&pSurf3 ) ) )
   {
       pSurf->Release();
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't QI DDS3\r\n" );
       return dwDXVersion;
   }

   // QI for IDirectDrawSurface3 succeeded. We must be at least DX5
   dwDXVersion = 0x500;
   pSurf3->Release();


  //-------------------------------------------------------------------------
   // DirectX 6.0 Checks
  //-------------------------------------------------------------------------

   // The IDirectDrawSurface4 interface was introduced with DX 6.0
   if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
                                      (VOID**)&pSurf4 ) ) )
   {
       pSurf->Release();
       pDDraw->Release();
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't QI DDS4\r\n" );
       return dwDXVersion;
   }

   // IDirectDrawSurface4 was create successfully. We must be at least DX6
   dwDXVersion = 0x600;
   pSurf4->Release();
   pSurf->Release();
   pDDraw->Release();


  //-------------------------------------------------------------------------
   // DirectX 6.1 Checks
  //-------------------------------------------------------------------------

   // Check for DMusic, which was introduced with DX6.1
   LPDIRECTMUSIC pDMusic = NULL;
   CoInitialize( NULL );
   hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
                          IID_IDirectMusic, (VOID**)&pDMusic );
   if( FAILED(hr) )
   {
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't create CLSID_DirectMusic\r\n" );
       return dwDXVersion;
   }

   // DirectMusic was created successfully. We must be at least DX6.1
   dwDXVersion = 0x601;
   pDMusic->Release();
   CoUninitialize();
   

  //-------------------------------------------------------------------------
   // DirectX 7.0 Checks
  //-------------------------------------------------------------------------

   // Check for DirectX 7 by creating a DDraw7 object
   LPDIRECTDRAW7 pDD7;
   DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( hDDrawDLL,
                                                      "DirectDrawCreateEx" );
   if( NULL == DirectDrawCreateEx )
   {
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't GetProcAddress DirectDrawCreateEx\r\n" );
       return dwDXVersion;
   }

   if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
                                   NULL ) ) )
   {
       FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't DirectDrawCreateEx\r\n" );
       return dwDXVersion;
   }

   // DDraw7 was created successfully. We must be at least DX7.0
   dwDXVersion = 0x700;
   pDD7->Release();


  //-------------------------------------------------------------------------
   // DirectX 8.0 Checks
  //-------------------------------------------------------------------------

   // Simply see if D3D8.dll exists.
   hD3D8DLL = LoadLibrary( "D3D8.DLL" );
   if( hD3D8DLL == NULL )
   {
      FreeLibrary( hDDrawDLL );
       OutputDebugString( "Couldn't LoadLibrary D3D8.DLL\r\n" );
       return dwDXVersion;
   }

   // D3D8.dll exists. We must be at least DX8.0
   dwDXVersion = 0x800;


  //-------------------------------------------------------------------------
   // DirectX 8.1 Checks
  //-------------------------------------------------------------------------

   // Simply see if dpnhpast.dll exists.
   hDPNHPASTDLL = LoadLibrary( "dpnhpast.dll" );
   if( hDPNHPASTDLL == NULL )
   {
      FreeLibrary( hDPNHPASTDLL );
       OutputDebugString( "Couldn't LoadLibrary dpnhpast.dll\r\n" );
       return dwDXVersion;
   }

   // dpnhpast.dll exists. We must be at least DX8.1
   dwDXVersion = 0x801;


  //-------------------------------------------------------------------------
   // End of checking for versions of DirectX
  //-------------------------------------------------------------------------

   // Close open libraries and return
   FreeLibrary( hDDrawDLL );
   FreeLibrary( hD3D8DLL );
   
   return dwDXVersion;
[COLOR=green][/color]

My computer specification:

AMD Athlon 64 2800+
MB ASUS K8V Socket 754 VIA K8T800
SB Audigy 2
3 GB RAM DDR 400 MHz PQI
AGP NVIDIA GeForce 7600GT 256 MB-Club 3D
Windows XP Pro SP2
DirectX 9.0c

kevin

QuoteIs this possible to do it in Playbasic or not ? In green is C code

Nope.

RavenVegetable

DX5 shipped with Win98. If they are still running Win95 or NT, and have played any game besides Minesweeper, it's likely been upgraded to at least DX3. Anything less than that, and they don't deserve to play any games.

kohai

DirectX3.0 was shipped back then, with Win95 ... in 1996 !!

Which means, nearly every computer on this planet using windows can launch a PB program ... So there's no real need of detection code :)

tomazmb

Hello,

It's not a problem today, but when PB will be 3D requireing DirectX 9 or 10 (I hope some day it will), what about then. I sure hope not that PB will stay at 2D forever. :unsure:

Have a nice day,

Tomaz
My computer specification:

AMD Athlon 64 2800+
MB ASUS K8V Socket 754 VIA K8T800
SB Audigy 2
3 GB RAM DDR 400 MHz PQI
AGP NVIDIA GeForce 7600GT 256 MB-Club 3D
Windows XP Pro SP2
DirectX 9.0c

empty

QuoteI sure hope not that PB will stay at 2D forever.
No, it won't. But then it'll also offer a way to detect the installed DirectX version. :)

tomazmb

Hello empty,

Good to hear that.

Have a nice day,

Tomaz
My computer specification:

AMD Athlon 64 2800+
MB ASUS K8V Socket 754 VIA K8T800
SB Audigy 2
3 GB RAM DDR 400 MHz PQI
AGP NVIDIA GeForce 7600GT 256 MB-Club 3D
Windows XP Pro SP2
DirectX 9.0c