Attribute VB_Name = "TurboMass" 'Functions specific to TurboMass '************************************************************* ' J. Hinshaw 12/08/97 '************************************************************** 'GLOBALS for TurboMass ' Global Const TM_CAPTION = "TurboMass" Global Const TM_EXE = "MLYNX3.EXE" 'keys for registry access; from C++ 5.0 WINNT.H, WINREG.H Global Const SYNCHRONIZE = &H100000 Global Const STANDARDRIGHTSREAD = &H20000 Global Const KEY_QUERY_VALUE = &H1 Global Const KEY_ENUMERATE_SUB_KEYS = &H8 Global Const KEY_NOTIFY = &H10 Global Const KEY_READ = (STANDARDRIGHTSREAD Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And Not SYNCHRONIZE Global Const HKEY_LOCAL_MACHINE = &H80000002 Global Const REG_SZ = &H1 Global Const TM_SUBKEY = "SOFTWARE\Perkin Elmer\TurboMass" Global Const TM_VERSION_VALUE_NAME = "Current Version" Global Const TM_PATH_VALUE_NAME = "Root Path" 'other constants needed Global Const ERROR_SUCCESS = 0 Global Const ERROR_FAILURE = -1 Global Const ERROR_MORE_DATA = 234 'WIN API Functions for registry Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Declare Function RegEnumKeyEx Lib "advapi32" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcdName As Long, lpReserved As Byte, lpClass As Byte, lpcbClass As Byte, lpftLastWriteTime As Byte) As Long Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, lpReserved As Long, lpType As Long, ByVal lpData As String, lpcdData As Long) As Long 'added for bringing spectrum window to front Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Byte '***************************************************************** 'retrieves turbomass registry info, or null if not found ' Paths are returned in long filename format. ' szTurboPath is the returned path to TurboMass ' szTurboVersion is the returned TurboMass version '****************************************************************** Function GetTurboRegistry(szTurboPath As String, szTurboVersion As String) As Long Dim hKeyRoot As Long Dim szSubKey As String Dim szValueName As String Dim szValueData As String 'get turbomass registry subkeys 'first get TurboMass version hKeyRoot = HKEY_LOCAL_MACHINE szSubKey = TM_SUBKEY szValueName = TM_VERSION_VALUE_NAME If RegGetValueString(hKeyRoot, szSubKey, szValueName, szValueData) <> ERROR_SUCCESS Then GetTurboRegistry = ERROR_FAILURE Exit Function End If 'return the version szTurboVersion = szValueData 'extend subkey to the version level, and get the Root Path to TurboMass szSubKey = TM_SUBKEY & "\" & szValueData szValueName = TM_PATH_VALUE_NAME If RegGetValueString(hKeyRoot, szSubKey, szValueName, szValueData) <> ERROR_SUCCESS Then GetTurboRegistry = ERROR_FAILURE Exit Function End If 'return the path szTurboPath = szValueData GetTurboRegistry = VALUE_SUCCESS End Function '****************************************************************** 'function to get a registry value. Handles STRING data only ' hKeyRoot is the root key containing the value ' szSubKey is the identifier of the subkey that contains the value ' szValueName is the name of the value to be queried ' szValueData is the returned data contained in the value ' Returns ERROR_SUCCESS if OK, or ERROR_FAILURE if not '****************************************************************** Function RegGetValueString(ByVal hKeyRoot As Long, ByVal szSubKey As String, ByVal szValueName As String, ByRef szValueData As String) As Long Dim hKey As Long Dim lResult As Long Dim lpType As Long Dim samDesired As Long Dim lpData As String * 1024 'assumes value is less than 1024 chars long Dim lpcdData As Long samDesired = KEY_READ 'security level 'open the subkey with WIN API call If RegOpenKeyEx(hKeyRoot, szSubKey, &O0, samDesired, hKey) <> ERROR_SUCCESS Then RegGetValueString = ERROR_FAILURE Exit Function End If 'read value data with WIN API call Do lResult = RegQueryValueEx(hKey, szValueName, ByVal 0&, lpType, lpData, lpcdData) Loop While lResult = ERROR_MORE_DATA If lResult <> ERROR_SUCCESS Then RegGetValueString = ERROR_FAILURE Exit Function End If 'check that we got a string back If lpType <> REG_SZ Then RegGetValueString = ERROR_FAILURE Exit Function End If 'place data in result szValueData = Left(lpData, lpcdData - 1) RegGetValueString = ERROR_SUCCESS End Function