How to get DirectX version using native VB
game_makerHi How to get DirectX version using native VB ?
Sr. GuapoDo you mean no D3DCaps or anything, just VB? I don't know... Why would you need to detect the DX version w/out DX calls in the first place?
Eric ColemanI found this in a quick google search, [code] Version Number DirectX Version 4.02.0095 DirectX 1.0 4.03.00.1096 DirectX 2.0 / 2.0a 4.04.0068 / 69 DirectX 3.0 / 3.0a Never Released DirectX 4.0 4.05.00.0155 DirectX 5.0 4.05.01.1721 / 1998 DirectX 5.0 (Released with Windows 98) 4.06.02.0436 DirectX 6.0 4.07.00.0700 DirectX 7.0 4.07.00.0716 DirectX 7.0a 4.08.00.0400 DirectX 8.0 4.08.01.0810 4.08.01.0881 DirectX 8.1 4.09.0000.0900 DirectX 9.0 4.09.0000.0901 DirectX 9.0a 4.09.0000.0902 DirectX 9.0b [/code] then simply read the registry key named "version" that's located at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX" Go to www.planetsourcecode.com if you need some code on how to read string values from the registry.
game_makerSr. Guapo : I need to tell the user what version he has to tell him if he/she can play my game or not [:)] Eric : exactly what I want 100% [:D] [code] Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal numBytes As Long) Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Function GetDirectXVersion() As Long Dim handle As Long, resString As String, resBinary() As Byte '// open the key, exit if not found If RegOpenKeyEx(&H80000002, "SOFTWARE\Microsoft\DirectX", 0, &H20019, handle) Then Exit Function '// prepare a 1K receiving resBinary ReDim resBinary(1023) As Byte '// read the registry value Call RegQueryValueEx(handle, "Version", 0, 0, resBinary(0), 1024) '// copy everything but the trailing null char resString = Space$(1023) CopyMemory ByVal resString, resBinary(0), 1023 '// close the registry key RegCloseKey handle resString = Left(resString, 12) If Not StrComp(resString, "4.05.00.0155", vbBinaryCompare) Then GetDirectXVersion = 50 If Not StrComp(resString, "4.05.01.1721", vbBinaryCompare) Then GetDirectXVersion = 50 If Not StrComp(resString, "4.05.01.1998", vbBinaryCompare) Then GetDirectXVersion = 50 If Not StrComp(resString, "4.06.02.0436", vbBinaryCompare) Then GetDirectXVersion = 60 If Not StrComp(resString, "4.07.00.0700", vbBinaryCompare) Then GetDirectXVersion = 70 If Not StrComp(resString, "4.07.00.0716", vbBinaryCompare) Then GetDirectXVersion = 71 If Not StrComp(resString, "4.08.00.0400", vbBinaryCompare) Then GetDirectXVersion = 80 If Not StrComp(resString, "4.08.01.0881", vbBinaryCompare) Then GetDirectXVersion = 85 If Not StrComp(resString, "4.09.00.0900", vbBinaryCompare) Then GetDirectXVersion = 90 If Not StrComp(resString, "4.09.00.0901", vbBinaryCompare) Then GetDirectXVersion = 91 If Not StrComp(resString, "4.09.00.0902", vbBinaryCompare) Then GetDirectXVersion = 92 End Function Private Function SwapEndian(ByVal dw As Long) As Long '// converts Big Endian DWord to Little Endian DWord CopyMemory ByVal VarPtr(SwapEndian) + 3, dw, 1 CopyMemory ByVal VarPtr(SwapEndian) + 2, ByVal VarPtr(dw) + 1, 1 CopyMemory ByVal VarPtr(SwapEndian) + 1, ByVal VarPtr(dw) + 2, 1 CopyMemory SwapEndian, ByVal VarPtr(dw) + 3, 1 End Function Private Sub Form_Load() MsgBox GetDirectXVersion End Sub [/code] x1 ,x2 ; 1 and 2 stands for alpha, beta x5 ..... x9 ; stands for .1 to .5
VBBROr you can use the dsetup DLL... I got this from the SDK Setup1 installer: [code]Option Explicit '--- Copied directly from the SDK setup project 'DirectX Setup Install constants Private Const DSETUP_DDRAWDRV As Long = 8 Private Const DSETUP_DSOUNDDRV As Long = 16 Private Const DSETUP_DXCORE As Long = 65536 Private Const DSETUP_DIRECTX As Long = (DSETUP_DXCORE Or DSETUP_DDRAWDRV Or DSETUP_DSOUNDDRV) Private Const DSETUP_TESTINSTALL As Long = 131072 Private Const DSETUP_NTINSTALL As Long = 524288 Private Const DSETUPERR_SUCCESS_RESTART As Long = 1 Private Const DSETUPERR_SUCCESS As Long = 0 Private Const DSETUP_VERSION As Long = &H40000 'DirectX Setup Install routines Private Declare Function DirectXSetup Lib "dsetup.dll" Alias "DirectXSetupA" (ByVal hWnd As Long, ByVal lpszRootPath As String, ByVal dwFlags As Long) As Long Private Declare Function DirectXSetupGetVersion Lib "dsetup.dll" (dwVersion As Long, dwRevision As Long) As Long '--- End of copied part 'Private Declarations Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Public Const EWX_FORCE = 4 Public Const EWX_LOGOFF = 0 Public Const EWX_REBOOT = 2 Public Const EWX_SHUTDOWN = 1 Sub Main() Dim fInstall As Boolean, ret As Long Dim lMajor As Long, lMinor As Long Dim gfDXReboot As Boolean Dim sTemp As String, sRootPath As String 'Check path validity sRootPath = Trim$(Command$) If sRootPath = "" Or Dir(sRootPath & "dsetup.dll") = "" Then MsgBox "Invalid command-line path.", vbCritical + vbOKOnly, "Error" End End If '--- Copied directly from the SDK setup project fInstall = False 'Do not install by default ret = DirectXSetupGetVersion(lMajor, lMinor) If ret = 0 Then 'failed to detect version fInstall = True Else lMajor = lMajor - (lMajor And DSETUP_VERSION) If lMajor < 8 Then '<------------------------- Note here: This checks for DirectX8... (major 8) fInstall = True Else 'do nothing, good version installed End If End If If fInstall Then 'Install DX8 ret = DirectXSetup(0, sRootPath, DSETUP_DIRECTX) If ret = DSETUPERR_SUCCESS Then 'Success do nothing ElseIf ret = DSETUPERR_SUCCESS_RESTART Then gfDXReboot = True Else MsgBox "An error occured whilst trying to install DirectX 8.0 on your computer. The program may not function properly.", vbCritical + vbOKOnly, "DirectX 8.0" End If End If '--- End of copied part If gfDXReboot Then If MsgBox("The computer needs to be restarted to finish the DirectX8.0 Setup. Click 'Yes' to restart now, or 'No' if you want to restart later.", vbQuestion + vbYesNo, "DirectX 8.0") = vbYes Then ExitWindowsEx EWX_REBOOT, 0 End If End If End Sub [/code] Create a new project, add a module and voila. Start this program with an argument that is a folder with the DIrectX8 install program. DSETUP.DLL must be on the same folder as the program. Then execute it and it will check the version THEN install the right version if it is needed. (You can just use your method above and mix it with the DirectSetup commands that are here)
Eric ColemanGame_maker, that list of directx versions isn't complete, and there is some variation with the last four numbers, so your test won't always work. And it will fail for testing for DirectX 9 because you're testing "4.09.00.0900" versus "4.09.0000.0900". Notice the extra zero's in the DirectX 9 versions. I think this might work a bit better, [code] Sub ParseVersion(ByVal strVersion As String, _ ByRef v1 As Long, _ ByRef v2 As Long, _ ByRef v3 As Long, _ ByRef v4 As Long) 'Split the version string into 4 different numbers. Dim strArray() As String strArray = Split(strVersion, ".") If UBound(strArray) >= 3 Then v1 = CLng(strArray(0)) v2 = CLng(strArray(1)) v3 = CLng(strArray(2)) v4 = CLng(strArray(3)) End If End Sub [/code] Instead of a large section of "If...Then..." statements, you could use the following code to check to see if the minimum version is installed. This also prevents your function from failing when a different version of directX is released that your function doesn't check for. [code]Dim DxVersion(0 to 3) As Long Call ParseVersion(resString, DxVersion(0), DxVersion(1), DxVersion(2), DxVersion(3)) 'Then just compare with the minimum version of directx needed for your program to run. If (DxVersion(1) < MinMajorVersion) Then Return False If (DxVersion(2) < MinMinorVersion) Then Return False If (DxVersion(3) < MinRevisionVersion) Then Return False 'If the program gets to this point, then the directx version is ' either equal to or greater than the minimum required version ' for your game. Return True [/code]
game_makerVBBR / Eric : Very nice Code [;)] But I don't know why I am getting 4.09.00.0900 in my computer ! But even if it's .0000000000000. your code will work [:)]