1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
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/.
10 * This file incorporates work covered by the following license notice:
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 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"API" script:
language=
"StarBasic">Declare Function RegOpenKeyEx Lib
"advapi32.dll
" Alias
"RegOpenKeyExA
" _
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
27 Declare Function RegQueryValueExString Lib
"advapi32.dll
" Alias
"RegQueryValueExA
" _
28 (ByVal hKey As Long, _
29 ByVal lpValueName As String, _
30 ByVal lpReserved As Long, _
33 lpcbData As Long) As Long
35 Declare Function RegQueryValueExLong Lib
"advapi32.dll
" Alias
"RegQueryValueExA
" _
36 (ByVal hKey As Long, _
37 ByVal lpValueName As String, _
38 ByVal lpReserved As Long, _
41 lpcbData As Long) As Long
43 Declare Function RegQueryValueExNULL Lib
"advapi32.dll
" Alias
"RegQueryValueExA
" _
44 (ByVal hKey As Long, _
45 ByVal lpValueName As String, _
46 ByVal lpReserved As Long, _
48 ByVal lpData As Long, _
49 lpcbData As Long) As Long
51 Declare Function RegCloseKeyA Lib
"advapi32.dll
" Alias
"RegCloseKey
" _
52 (ByVal hKey As Long) As Long
55 Public Const HKEY_CLASSES_ROOT =
&H80000000
56 Public Const HKEY_CURRENT_USER =
&H80000001
57 Public Const HKEY_LOCAL_MACHINE =
&H80000002
58 Public Const HKEY_USERS =
&H80000003
59 Public Const KEY_ALL_ACCESS =
&H3F
60 Public Const REG_OPTION_NON_VOLATILE =
0
61 Public Const REG_SZ As Long =
1
62 Public Const REG_DWORD As Long =
4
63 Public Const ERROR_NONE =
0
64 Public Const ERROR_BADDB =
1
65 Public Const ERROR_BADKEY =
2
66 Public Const ERROR_CANTOPEN =
3
67 Public Const ERROR_CANTREAD =
4
68 Public Const ERROR_CANTWRITE =
5
69 Public Const ERROR_OUTOFMEMORY =
6
70 Public Const ERROR_INVALID_PARAMETER =
7
71 Public Const ERROR_ACCESS_DENIED =
8
72 Public Const ERROR_INVALID_PARAMETERS =
87
73 Public Const ERROR_NO_MORE_ITEMS =
259
74 'Public Const KEY_READ =
&H20019
77 Function OpenRegKey(lBaseKey As Long, sKeyName As String) As Variant
81 lRetValue = RegOpenKeyEx(lBaseKey, sKeyName,
0, KEY_ALL_ACCESS, hKey)
82 ' lRetValue = QueryValue(HKEY_LOCAL_MACHINE,
"SOFTWARE\Microsoft\Outlook Express\
5.0\Default Settings
",
"Revocation Checking
")
83 If hKey
<> 0 Then
86 OpenRegKey() = lRetValue
90 Function GetDefaultPath(CurOffice as Integer) As String
93 Select Case Wizardmode
95 Index = Applications(CurOffice,SBAPPLKEY)
96 If GetGUIType =
1 Then
' Windows
97 sPath = QueryValue(HKEY_LOCAL_MACHINE, sKeyName(Index), sValueName(Index))
101 If sPath =
"" Then
104 GetDefaultPath = sPath
109 Function GetTemplateDefaultPath(Index as Integer) As String
110 Dim sLocTemplatePath as String
111 Dim sLocProgrampath as String
112 Dim Progstring as String
113 Dim PathList()as String
114 Dim Maxindex as Integer
115 Dim OldsLocTemplatePath
116 Dim sTemplateKeyName as String
117 Dim sTemplateValueName as String
118 On Local Error Goto NOVAlIDSYSTEMPATH
119 Select Case WizardMode
121 If GetGUIType =
1 Then
' Windows
122 ' Template directory of Office
97
123 sTemplateKeyName =
"Software\Microsoft\Office\
8.0\Common\FileNew\LocalTemplates
"
124 sTemplateValueName =
""
125 sLocTemplatePath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName)
127 If sLocTemplatePath =
"" Then
128 ' Retrieve the template directory of Office
2000
129 ' Unfortunately there is no existing note about the template directory in
130 ' the whole registry.
132 ' Programdirectory of Office
2000
133 sTemplateKeyName =
"Software\Microsoft\Office\
9.0\Common\InstallRoot
"
134 sTemplateValueName =
"Path
"
135 sLocProgrampath = QueryValue(HKEY_LOCAL_MACHINE, sTemplateKeyName, sTemplateValueName)
136 If sLocProgrampath
<> "" Then
137 If Right(sLocProgrampath,
1)
<> "\
" Then
138 sLocProgrampath = sLocProgrampath
& "\
"
140 PathList() = ArrayoutofString(sLocProgrampath,
"\
",Maxindex)
141 Progstring =
"\
" & PathList(Maxindex-
1)
& "\
"
142 OldsLocTemplatePath = DeleteStr(sLocProgramPath,Progstring)
144 sLocTemplatePath = OldsLocTemplatePath
& "\
" & "Templates
"
146 ' Does this subdirectory
"templates
" exist at all
147 If oUcb.Exists(sLocTemplatePath) Then
148 ' If Not the main directory of the office is the base
149 sLocTemplatePath = OldsLocTemplatePath
152 sLocTemplatePath = SOWorkPath
155 GetTemplateDefaultPath = ConvertToUrl(sLocTemplatePath)
157 GetTemplateDefaultPath = SOWorkPath
161 If Err
<> 0 Then
162 GetTemplateDefaultPath() = SOWorkPath
169 Function QueryValueEx(ByVal lhKey, ByVal szValueName As String, vValue As String) As Long
177 On Error GoTo QueryValueExError
179 lrc = RegQueryValueExNULL(lhKey, szValueName,
0&, lType,
0&, cch)
180 If lrc
<> ERROR_NONE Then Error
5
183 sValue = String(cch,
0)
184 lrc = RegQueryValueExString(lhKey, szValueName,
0&, lType, sValue, cch)
185 If lrc = ERROR_NONE Then
186 vValue = Left$(sValue, cch)
191 lrc = RegQueryValueExLong(lhKey, szValueName,
0&, lType, lValue, cch)
192 If lrc = ERROR_NONE Then
202 Resume QueryValueExExit
206 Function QueryValue(BaseKey As Long, sKeyName As String, sValueName As String) As Variant
207 Dim lRetVal As Long
' Returnvalue API-Call
208 Dim hKey As Long
' One key handle
209 Dim vValue As String
' Key value
211 lRetVal = RegOpenKeyEx(BaseKey, sKeyName,
0, KEY_ALL_ACCESS, hKey)
212 lRetVal = QueryValueEx(hKey, sValueName, vValue)