home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Programmer'…arterly (Limited Edition)
/
Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso
/
code
/
ch14code
/
main.bas
< prev
next >
Wrap
BASIC Source File
|
1995-08-08
|
4KB
|
134 lines
Attribute VB_Name = "Module1"
Option Explicit
' Registration APIs used to check entry.
#If Win16 Then
Declare Function RegOpenKey Lib "Shell" _
(ByVal HKeyIn As Long, _
ByVal LPCSTR As String, _
HKeyOut As Long) _
As Long
Declare Function RegCloseKey Lib "Shell" _
(ByVal HKeyIn As Long) _
As Long
Declare Function RegQueryValue Lib "Shell" _
(ByVal HKeyIn As Long, _
ByVal SubKey As String, _
ByVal KeyValue As String, _
KeyValueLen As Long) _
As Long
Declare Function RegSetValue Lib "Shell" _
(ByVal HKeyIn As Long, _
ByVal SubKey As String, _
ByVal lType As Long, _
ByVal strNewValue As String, _
ByVal lIngnored As Long) _
As Long
Declare Sub RegDeleteKey Lib "Shell" _
(ByVal HKeyIn As Long, _
ByVal SubKeyName As String)
#Else
Declare Function RegOpenKey Lib "advapi32" _
Alias "RegOpenKeyA" _
(ByVal HKeyIn As Long, _
ByVal LPCSTR As String, _
HKeyOut As Long) _
As Long
Declare Function RegOpenKeyEx Lib "advapi32" _
Alias "RegOpenKeyExA" _
(ByVal HKeyIn As Long, ByVal LPCSTR _
As String, ByVal dwRes _
As Long, ByVal dwAccess _
As Long, HKeyOut As _
Long) As Long _
Declare Function RegCloseKey Lib "advapi32" _
(ByVal HKeyIn As Long) _
As Long
Declare Function RegQueryValue Lib "advapi32" _
Alias "RegQueryValueA" _
(ByVal HKeyIn As Long, _
ByVal SubKey As String, _
ByVal KeyValue As String, _
KeyValueLen As Long) _
As Long
Declare Function RegSetValue Lib "advapi32" _
Alias "RegSetValueA" _
(ByVal HKeyIn As Long, _
ByVal SubKey As String, _
ByVal lType As Long, _
ByVal strNewValue As String, _
ByVal lIngnored As Long) _
As Long
Declare Function RegDeleteKey Lib "advapi32" _
Alias "RegDeleteKeyA" _
(ByVal HKeyIn As Long, _
ByVal SubKeyName As String) _
As Long
#End If
#If Win16 Then
Const HKEY_CLASSES_ROOT = &H1
#Else
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
#End If
Public Const ERROR_SUCCESS = 0
Sub Main()
' Check registration entries on start-up.
CheckRegistrationEntry "Store.Application"
' If there was a command line, try to load
' the file.
If Len(Command$()) Then
frmStore.OpenFile Command$()
End If
' Show form.
frmStore.Show
End Sub
Sub CheckRegistrationEntry(strSearchKey As String)
Dim hkroot As Long, lError As Long, lLen As Long
Dim strKeyID As String, strKeyDesc As String
Dim strAppName As String
' Get current application path and file name.
strAppName = App.Path & "\" & App.EXEName & ".EXE" & _
" %1"
lLen = 255
' Specify subentry value to check.
strKeyID = "command"
' Initalize key description (value returned by RegQueryValue).
strKeyDesc = String(lLen, 0)
' Get the registry entry for the Open key.
lError = RegOpenKey(HKEY_CLASSES_ROOT, strSearchKey & _
"\shell\open", hkroot)
' Get the value of the entry.
lError = RegQueryValue(hkroot, strKeyID, strKeyDesc, lLen)
' If RegOpenKey or RegQueryValue return an error,
' display a message and end.
If lError Then
MsgBox "Couldn't find registry entry. Please reinstall" & _
"the application."
End
End If
' Check the value against the current installation.
If Left(strKeyDesc, lLen - 1) <> strAppName Then
' If it doesn't match, change the registered value.
lError = RegSetValue(hkroot, strKeyID, 1, strAppName, 0)
End If
' If RegOpenKey or RegQueryValue return an error,
' display a message and end.
If lError Then
MsgBox "Couldn't update registry entry."
End
End If
' Close the registration key.
lError = RegCloseKey(hkroot)
End Sub