Detect DirectX Version: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
No edit summary |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{ | {{PageAuthor|jason379}} | ||
== Description == | == Description == | ||
This code will return the DirectX version number on the stack, or zero if DirectX is not installed. The return value is an integer | This code will return the DirectX version number on the stack, or zero if DirectX is not installed. The return value is an integer concatenating the major and minor version: "801" for version 8.1, "900" for version 9.0. | ||
== Example == | == Example == | ||
Line 14: | Line 12: | ||
MessageBox "MB_OK" "Requires DirectX 9.0 or later." | MessageBox "MB_OK" "Requires DirectX 9.0 or later." | ||
Abort | Abort | ||
</highlight-nsis> | |||
== Safer Example == | |||
Just in case if Microsoft decides to modify the key name/version (as it doesn't show 1000 on Vista as it should) and the detection fails it is safer to simply warn the user but not to exit - in that case use this: | |||
<highlight-nsis> | |||
Call GetDXVersion | |||
Pop $R3 | |||
IntCmp $R3 900 +2 0 +2 | |||
MessageBox "MB_OK" "Requires DirectX 9.0 or later. Please update your DirectX." | |||
</highlight-nsis> | </highlight-nsis> | ||
Line 23: | Line 30: | ||
Push $1 | Push $1 | ||
ClearErrors | |||
ReadRegStr $0 HKLM "Software\Microsoft\DirectX" "Version" | ReadRegStr $0 HKLM "Software\Microsoft\DirectX" "Version" | ||
IfErrors noDirectX | IfErrors noDirectX | ||
Line 40: | Line 48: | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Other Products Version Detection Functions]] | |||
[[Category:DirectX]] |
Latest revision as of 06:38, 11 August 2009
Author: jason379 (talk, contrib) |
Description
This code will return the DirectX version number on the stack, or zero if DirectX is not installed. The return value is an integer concatenating the major and minor version: "801" for version 8.1, "900" for version 9.0.
Example
Here is an example of how it can be used:
Call GetDXVersion Pop $R3 IntCmp $R3 900 +3 0 +3 MessageBox "MB_OK" "Requires DirectX 9.0 or later." Abort
Safer Example
Just in case if Microsoft decides to modify the key name/version (as it doesn't show 1000 on Vista as it should) and the detection fails it is safer to simply warn the user but not to exit - in that case use this:
Call GetDXVersion Pop $R3 IntCmp $R3 900 +2 0 +2 MessageBox "MB_OK" "Requires DirectX 9.0 or later. Please update your DirectX."
The Function
And here is the code:
Function GetDXVersion Push $0 Push $1 ClearErrors ReadRegStr $0 HKLM "Software\Microsoft\DirectX" "Version" IfErrors noDirectX StrCpy $1 $0 2 5 ; get the minor version StrCpy $0 $0 2 2 ; get the major version IntOp $0 $0 * 100 ; $0 = major * 100 + minor IntOp $0 $0 + $1 Goto done noDirectX: StrCpy $0 0 done: Pop $1 Exch $0 FunctionEnd