Go Back   Winamp & Shoutcast Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 5th January 2003, 10:37   #1
quentin
Junior Member
 
Join Date: Aug 2001
Location: austria
Posts: 43
[vb] here's some code, is there another way to retrieve winamp.exe path?

hi there.

i'm writing a plugin where i have to get the path + filename to winamp.exe

here's some code that i use at the moment, it returns the path to my dll so i cut the filename and the last directory (which should be plugins\)

Quote:
Public Declare Function GetModuleFileName Lib "kernel32" _
Alias "GetModuleFileNameA" _
(ByVal hModule As Long, _
ByVal lpFileName As String, _
ByVal nSize As Long) As Long
Quote:
Dim strFileName As String
Dim lngCount As Long
strFileName = String(512, 0)
lngCount = GetModuleFileName(App.hInstance, strFileName, 512)
strFileName = Left(strFileName, lngCount)

is there another, cleaner solution to solve this in visual basic ?

thanks and greetz
quentin
quentin is offline   Reply With Quote
Old 5th January 2003, 16:40   #2
Kaboon
Moderator
 
Kaboon's Avatar
 
Join Date: Jun 2000
Location: Netherlands
Posts: 2,494
Send a message via ICQ to Kaboon
Maybe you could extract it from the registry (RegQueryValueEx)? The path to Winamp is stored in HKEY_CURRENT_USER\Software\Winamp. Winamp.exe should be in that directory too...
Kaboon is offline   Reply With Quote
Old 5th January 2003, 17:36   #3
quentin
Junior Member
 
Join Date: Aug 2001
Location: austria
Posts: 43
"should" be, that doesn't sound good
but i'll sure have a look and try it cause the way i made it doesn't work if your plugins directory is somewhere else :/

thanks!
quentin is offline   Reply With Quote
Old 19th January 2003, 23:51   #4
jmoschetti45
Senior Member
 
jmoschetti45's Avatar
 
Join Date: Oct 2002
Location: Marquette, MI
Posts: 101
Send a message via AIM to jmoschetti45 Send a message via Yahoo to jmoschetti45
If you are trying to open winamp.exe yes:
Put this in your Declarations:

Public Const WINAMP_PATH As String = "C:\Program Files\Winamp\winamp.exe"

And The Function:

Public Function WinAMP_Start() As Boolean
Dim ReturnValue As Double
ReturnValue = Shell(WINAMP_PATH)
If ReturnValue <> 0 Then
WinAMP_Start = True
Else
WinAMP_Start = False
End If
End Function

This allows you to find and/or execute winamp.exe

(I'm Using it in my program so i know it works!)
jmoschetti45 is offline   Reply With Quote
Old 20th January 2003, 16:20   #5
quentin
Junior Member
 
Join Date: Aug 2001
Location: austria
Posts: 43
you didn't get the point

not every user has installed winamp in "C:\Program Files\Winamp\winamp.exe"

reading the string from the registry worked, thanks!
quentin is offline   Reply With Quote
Old 20th January 2003, 19:12   #6
jmoschetti45
Senior Member
 
jmoschetti45's Avatar
 
Join Date: Oct 2002
Location: Marquette, MI
Posts: 101
Send a message via AIM to jmoschetti45 Send a message via Yahoo to jmoschetti45
Could you put a copy of the code here so i can use it in my program
jmoschetti45 is offline   Reply With Quote
Old 21st January 2003, 06:09   #7
quentin
Junior Member
 
Join Date: Aug 2001
Location: austria
Posts: 43
sure, i'll post it in about 10 hours when i'm back home
quentin is offline   Reply With Quote
Old 21st January 2003, 16:20   #8
quentin
Junior Member
 
Join Date: Aug 2001
Location: austria
Posts: 43
Put this in your module:

Quote:
Public Declare Function GetModuleFileName Lib "kernel32" _
Alias "GetModuleFileNameA" _
(ByVal hModule As Long, _
ByVal lpFileName As String, _
ByVal nSize As Long) As Long

' Types Definition
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

'API Declarations
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, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long

'Types Enum Definition
Public Enum T_KeyClasses
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
End Enum

'Constants Definition
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_EVENT = &H1
Private Const KEY_NOTIFY = &H10
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_EXECUTE = (KEY_READ)
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const REG_BINARY = 3
Private Const REG_CREATED_NEW_KEY = &H1
Private Const REG_DWORD = 4
Private Const REG_DWORD_BIG_ENDIAN = 5
Private Const REG_DWORD_LITTLE_ENDIAN = 4
Private Const REG_EXPAND_SZ = 2
Private Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Private Const REG_LINK = 6
Private Const REG_MULTI_SZ = 7
Private Const REG_NONE = 0
Private Const REG_SZ = 1
Private Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
Private Const REG_NOTIFY_CHANGE_LAST_SET = &H4
Private Const REG_NOTIFY_CHANGE_NAME = &H1
Private Const REG_NOTIFY_CHANGE_SECURITY = &H8
Private Const REG_OPTION_BACKUP_RESTORE = 4
Private Const REG_OPTION_CREATE_LINK = 2
Private Const REG_OPTION_NON_VOLATILE = 0
Private Const REG_OPTION_RESERVED = 0
Private Const REG_OPTION_VOLATILE = 1
Private Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
Private Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)
and this function:

Quote:
'Get a specific Registry Value (to access the Default Registry Key Value set sKey parameter as "")
Public Function GetRegValue(KeyRoot As T_KeyClasses, Path As String, sKey As String) As String
Dim hKey As Long
Dim KeyValType As Long
Dim KeyValSize As Long
Dim KeyVal As String
Dim tmpVal As String
Dim res As Long
Dim i As Integer

res = RegOpenKeyEx(KeyRoot, Path, 0, KEY_ALL_ACCESS, hKey)
If res <> 0 Then GoTo Errore
tmpVal = String(1024, 0)
KeyValSize = 1024
res = RegQueryValueEx(hKey, sKey, 0, KeyValType, tmpVal, KeyValSize)
If res <> 0 Then GoTo Errore
If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then
tmpVal = Left(tmpVal, KeyValSize - 1)
Else
tmpVal = Left(tmpVal, KeyValSize)
End If
Select Case KeyValType
Case REG_SZ
KeyVal = tmpVal
Case REG_DWORD
For i = Len(tmpVal) To 1 Step -1
KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1)))
Next
KeyVal = Format("&h" + KeyVal)
End Select
GetRegValue = KeyVal
RegCloseKey hKey
Exit Function
Errore:
GetRegValue = ""
RegCloseKey hKey
End Function

now you can call the function using this row:

Quote:
waPath = GetRegValue(HKEY_CURRENT_USER, "Software\Winamp", "")
waPath = waPath & "\winamp.exe"

that did the job for me!

thanks for the hint Kaboon


bye
quentin
quentin is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump