API.xba 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--
  4. * This file is part of the LibreOffice project.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  12. * Licensed to the Apache Software Foundation (ASF) under one or more
  13. * contributor license agreements. See the NOTICE file distributed
  14. * with this work for additional information regarding copyright
  15. * ownership. The ASF licenses this file to you under the Apache
  16. * License, Version 2.0 (the "License"); you may not use this file
  17. * except in compliance with the License. You may obtain a copy of
  18. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  19. -->
  20. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="API" script:language="StarBasic">Declare Function RegOpenKeyEx Lib &quot;advapi32.dll&quot; Alias &quot;RegOpenKeyExA&quot; _
  21. (ByVal hKey As Long, _
  22. ByVal lpSubKey As String, _
  23. ByVal ulOptions As Long, _
  24. ByVal samDesired As Long, _
  25. phkResult As Long) As Long
  26. Declare Function RegQueryValueExString Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; _
  27. (ByVal hKey As Long, _
  28. ByVal lpValueName As String, _
  29. ByVal lpReserved As Long, _
  30. lpType As Long, _
  31. lpData As String, _
  32. lpcbData As Long) As Long
  33. Declare Function RegQueryValueExLong Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; _
  34. (ByVal hKey As Long, _
  35. ByVal lpValueName As String, _
  36. ByVal lpReserved As Long, _
  37. lpType As Long, _
  38. lpData As Long, _
  39. lpcbData As Long) As Long
  40. Declare Function RegQueryValueExNULL Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; _
  41. (ByVal hKey As Long, _
  42. ByVal lpValueName As String, _
  43. ByVal lpReserved As Long, _
  44. lpType As Long, _
  45. ByVal lpData As Long, _
  46. lpcbData As Long) As Long
  47. Declare Function RegCloseKeyA Lib &quot;advapi32.dll&quot; Alias &quot;RegCloseKey&quot; _
  48. (ByVal hKey As Long) As Long
  49. Public Const HKEY_CLASSES_ROOT = &amp;H80000000
  50. Public Const HKEY_CURRENT_USER = &amp;H80000001
  51. Public Const HKEY_LOCAL_MACHINE = &amp;H80000002
  52. Public Const HKEY_USERS = &amp;H80000003
  53. Public Const KEY_ALL_ACCESS = &amp;H3F
  54. Public Const REG_OPTION_NON_VOLATILE = 0
  55. Public Const REG_SZ As Long = 1
  56. Public Const REG_DWORD As Long = 4
  57. Public Const ERROR_NONE = 0
  58. Public Const ERROR_BADDB = 1
  59. Public Const ERROR_BADKEY = 2
  60. Public Const ERROR_CANTOPEN = 3
  61. Public Const ERROR_CANTREAD = 4
  62. Public Const ERROR_CANTWRITE = 5
  63. Public Const ERROR_OUTOFMEMORY = 6
  64. Public Const ERROR_INVALID_PARAMETER = 7
  65. Public Const ERROR_ACCESS_DENIED = 8
  66. Public Const ERROR_INVALID_PARAMETERS = 87
  67. Public Const ERROR_NO_MORE_ITEMS = 259
  68. &apos;Public Const KEY_READ = &amp;H20019
  69. Function OpenRegKey(lBaseKey As Long, sKeyName As String) As Variant
  70. Dim LocKeyValue
  71. Dim hKey as Long
  72. Dim lRetValue as Long
  73. lRetValue = RegOpenKeyEx(lBaseKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
  74. &apos; lRetValue = QueryValue(HKEY_LOCAL_MACHINE, &quot;SOFTWARE\Microsoft\Outlook Express\5.0\Default Settings&quot;, &quot;Revocation Checking&quot;)
  75. If hKey &lt;&gt; 0 Then
  76. RegCloseKeyA (hKey)
  77. End If
  78. OpenRegKey() = lRetValue
  79. End Function
  80. Function GetDefaultPath(CurOffice as Integer) As String
  81. Dim sPath as String
  82. Dim Index as Integer
  83. Select Case Wizardmode
  84. Case SBMICROSOFTMODE
  85. Index = Applications(CurOffice,SBAPPLKEY)
  86. If GetGUIType = 1 Then &apos; Windows
  87. sPath = QueryValue(HKEY_LOCAL_MACHINE, sKeyName(Index), sValueName(Index))
  88. Else
  89. sPath = &quot;&quot;
  90. End If
  91. If sPath = &quot;&quot; Then
  92. sPath = SOWorkPath
  93. End If
  94. GetDefaultPath = sPath
  95. End Select
  96. End Function
  97. Function GetTemplateDefaultPath(Index as Integer) As String
  98. Dim sLocTemplatePath as String
  99. Dim sLocProgrampath as String
  100. Dim Progstring as String
  101. Dim PathList()as String
  102. Dim Maxindex as Integer
  103. Dim OldsLocTemplatePath
  104. Dim sTemplateKeyName as String
  105. Dim sTemplateValueName as String
  106. On Local Error Goto NOVAlIDSYSTEMPATH
  107. Select Case WizardMode
  108. Case SBMICROSOFTMODE
  109. If GetGUIType = 1 Then &apos; Windows
  110. &apos; Template directory of Office 97
  111. sTemplateKeyName = &quot;Software\Microsoft\Office\8.0\Common\FileNew\LocalTemplates&quot;
  112. sTemplateValueName = &quot;&quot;
  113. sLocTemplatePath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName)
  114. If sLocTemplatePath = &quot;&quot; Then
  115. &apos; Retrieve the template directory of Office 2000
  116. &apos; Unfortunately there is no existing note about the template directory in
  117. &apos; the whole registry.
  118. &apos; Programdirectory of Office 2000
  119. sTemplateKeyName = &quot;Software\Microsoft\Office\9.0\Common\InstallRoot&quot;
  120. sTemplateValueName = &quot;Path&quot;
  121. sLocProgrampath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName)
  122. If sLocProgrampath &lt;&gt; &quot;&quot; Then
  123. If Right(sLocProgrampath, 1) &lt;&gt; &quot;\&quot; Then
  124. sLocProgrampath = sLocProgrampath &amp; &quot;\&quot;
  125. End If
  126. PathList() = ArrayoutofString(sLocProgrampath,&quot;\&quot;,Maxindex)
  127. Progstring = &quot;\&quot; &amp; PathList(Maxindex-1) &amp; &quot;\&quot;
  128. OldsLocTemplatePath = DeleteStr(sLocProgramPath,Progstring)
  129. sLocTemplatePath = OldsLocTemplatePath &amp; &quot;\&quot; &amp; &quot;Templates&quot;
  130. &apos; Does this subdirectory &quot;templates&quot; exist at all
  131. If oUcb.Exists(sLocTemplatePath) Then
  132. &apos; If Not the main directory of the office is the base
  133. sLocTemplatePath = OldsLocTemplatePath
  134. End If
  135. Else
  136. sLocTemplatePath = SOWorkPath
  137. End If
  138. End If
  139. GetTemplateDefaultPath = ConvertToUrl(sLocTemplatePath)
  140. Else
  141. GetTemplateDefaultPath = SOWorkPath
  142. End If
  143. End Select
  144. NOVALIDSYSTEMPATH:
  145. If Err &lt;&gt; 0 Then
  146. GetTemplateDefaultPath() = SOWorkPath
  147. Resume ONITGOES
  148. ONITGOES:
  149. End If
  150. End Function
  151. Function QueryValueEx(ByVal lhKey, ByVal szValueName As String, vValue As String) As Long
  152. Dim cch As Long
  153. Dim lrc As Long
  154. Dim lType As Long
  155. Dim lValue As Long
  156. Dim sValue As String
  157. Dim Empty
  158. On Error GoTo QueryValueExError
  159. lrc = RegQueryValueExNULL(lhKey, szValueName, 0&amp;, lType, 0&amp;, cch)
  160. If lrc &lt;&gt; ERROR_NONE Then Error 5
  161. Select Case lType
  162. Case REG_SZ:
  163. sValue = String(cch, 0)
  164. lrc = RegQueryValueExString(lhKey, szValueName, 0&amp;, lType, sValue, cch)
  165. If lrc = ERROR_NONE Then
  166. vValue = Left$(sValue, cch)
  167. Else
  168. vValue = Empty
  169. End If
  170. Case REG_DWORD:
  171. lrc = RegQueryValueExLong(lhKey, szValueName, 0&amp;, lType, lValue, cch)
  172. If lrc = ERROR_NONE Then
  173. vValue = lValue
  174. End If
  175. Case Else
  176. lrc = -1
  177. End Select
  178. QueryValueExExit:
  179. QueryValueEx = lrc
  180. Exit Function
  181. QueryValueExError:
  182. Resume QueryValueExExit
  183. End Function
  184. Function QueryValue(BaseKey As Long, sKeyName As String, sValueName As String) As Variant
  185. Dim lRetVal As Long &apos; Returnvalue API-Call
  186. Dim hKey As Long &apos; One key handle
  187. Dim vValue As String &apos; Key value
  188. lRetVal = RegOpenKeyEx(BaseKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
  189. lRetVal = QueryValueEx(hKey, sValueName, vValue)
  190. RegCloseKeyA (hKey)
  191. QueryValue = vValue
  192. End Function
  193. </script:module>