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 / ch24code / regadd.bas < prev    next >
Encoding:
BASIC Source File  |  1995-08-15  |  1.9 KB  |  61 lines

  1. Attribute VB_Name = "modMain"
  2. ' Adds an entry to VB.INI that will add an addin to
  3. ' VB's Addins dialog box when VB is started.
  4. Option Explicit
  5.  
  6. #If Win16 Then
  7.     Declare Function WritePrivateProfileString _
  8.         Lib "KERNEL" (ByVal AppName$, _
  9.         ByVal KeyName$, ByVal keydefault$, _
  10.         ByVal FileName$) As Integer
  11.     Declare Function GetPrivateProfileString _
  12.         Lib "KERNEL" (ByVal AppName$, _
  13.         ByVal KeyName$, ByVal keydefault$, _
  14.         ByVal ReturnString$, _
  15.         ByVal NumBytes As Integer, _
  16.         ByVal FileName$) As Integer
  17. #Else
  18.     Declare Function WritePrivateProfileString _
  19.         Lib "KERNEL32" Alias _
  20.         "WritePrivateProfileStringA" _
  21.         (ByVal AppName$, ByVal KeyName$, _
  22.         ByVal keydefault$, ByVal FileName$) _
  23.         As Integer
  24.     Declare Function GetPrivateProfileString _
  25.         Lib "KERNEL32" Alias _
  26.         "GetPrivateProfileStringA" (ByVal AppName$, _
  27.         ByVal KeyName$, ByVal keydefault$, _
  28.         ByVal ReturnString$, ByVal NumBytes As Integer, _
  29.         ByVal FileName$) As Integer
  30. #End If
  31.  
  32. Dim strAddIn As String, strSetting As String
  33.  
  34. Sub main()
  35.     ' Install the add-in
  36.     ' Name of addin = applicationname.classname
  37.     strAddIn = "RegEditAddin.Application"
  38.     ' 1 loads addin, 0 does not load
  39.     strSetting = "1"
  40.     ' Add entry to VB.INI.
  41.     Dim sSection As String
  42.     #If Win16 Then
  43.         sSection = "Add-Ins16"
  44.     #Else
  45.         sSection = "Add-Ins32"
  46.     #End If
  47.     If WritePrivateProfileString(sSection, strAddIn, _
  48.         strSetting, "vb.ini") Then
  49.         ' Success.
  50.     Else
  51.         ' Notify user that add-in couldn't be registered.
  52.         MsgBox "Addin could not be registered in VB.INI. " & _
  53.         "Add these lines to VB.INI and restart Visual Basic: " & _
  54.         Chr(13) & _
  55.         "[" & sSection & "]" & _
  56.         Chr(13) & _
  57.         strAddIn, vbExclamation, "Install Addin"
  58.     End If
  59. End Sub
  60.  
  61.