ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/include/wloadlibrary.inc
Revision: 56
Committed: Mon Mar 6 10:20:02 2017 UTC (7 years, 8 months ago) by tony
Original Path: ibx/trunk/fbintf/client/include/wloadlibrary.inc
File size: 5075 byte(s)
Log Message:
Committing updates for Trunk

File Contents

# Content
1 procedure TFBClientAPI.LoadIBLibrary;
2
3 function IsValidHandle(aHandle: TLibHandle): boolean;
4 begin
5 Result := aHandle > HINSTANCE_ERROR;
6 end;
7
8 function DoLoadLibrary(LibName: string): TLibHandle;
9 begin
10 Result := LoadLibrary(PChar(LibName));
11 if IsValidHandle(Result) then
12 begin
13 FFBLibraryName := ExtractFileName(LibName);
14 FFBLibraryPath := ExtractFileDir(LibName);
15 end;
16 end;
17
18 function GetSpecialFolder(const CSIDL: integer) : string;
19 {$IFDEF FPC}
20 begin
21 Result := GetWindowsSpecialDir(CSIDL);
22 end;
23 {$ELSE}
24 var
25 RecPath : PChar;
26 begin
27 RecPath := StrAlloc(MAX_PATH);
28 try
29 FillChar(RecPath^, MAX_PATH, 0);
30 if SHGetSpecialFolderPath(0, RecPath, CSIDL, false)
31 then result := RecPath
32 else result := '';
33 finally
34 StrDispose(RecPath);
35 end;
36 end;
37 {$ENDIF}
38
39 var InstallDir: string;
40 dllPathName: string;
41 oldFirebirdEV: string;
42 begin
43 if IsValidHandle(IBLibrary) then Exit;
44
45 {First try any user override}
46 dllPathName := GetOverrideLibName;
47 if dllPathName <> '' then
48 begin
49 IBLibrary := DoLoadLibrary(dllPathName);
50 FOwnsIBLibrary := IsValidHandle(IBLibrary);
51 Exit;
52 end;
53
54 {Then look in application installation directory}
55 InstallDir := ExtractFilePath(Paramstr(0)); {Using ParamStr(0) assumes windows conventions}
56
57 //First look for Firebird Embedded Server in installation dir
58 if FileExists(InstallDir + FIREBIRD_EMBEDDED) then
59 begin
60 dllPathName := InstallDir + FIREBIRD_EMBEDDED;
61 IBLibrary := DoLoadLibrary(dllPathName)
62 end
63 else
64 //Otherwise look for Firebird Client in installation dir
65 if FileExists(InstallDir + FIREBIRD_CLIENT) then
66 begin
67 //assume firebird.conf and firebird.msg in same dir
68 oldFirebirdEV := GetEnvironmentVariable('FIREBIRD');
69 SetEnvironmentVariable('FIREBIRD',PChar(InstallDir));
70 dllPathName := InstallDir + FIREBIRD_CLIENT;
71 try
72 IBLibrary := DoLoadLibrary(dllPathName)
73 finally
74 if not IsValidHandle(IBLibrary) then
75 SetEnvironmentVariable('FIREBIRD',PChar(oldFirebirdEV)); {restore}
76 end;
77 end;
78
79 // writeln('Dir = ',InstallDir);
80 {If FIREBIRD environment variable available then try this}
81 if not IsValidHandle(IBLibrary) then
82 begin
83 InstallDir := GetEnvironmentVariable('FIREBIRD');
84 if (length(InstallDir) > 0) and (InstallDir[length(InstallDir)] <> DirectorySeparator) then
85 InstallDir := InstallDir + DirectorySeparator;
86 if (InstallDir <> '') and FileExists(InstallDir + FIREBIRD_CLIENT) then
87 begin
88 //assume firebird.conf and firebird.msg in same dir
89 dllPathName := InstallDir + FIREBIRD_CLIENT;
90 IBLibrary := DoLoadLibrary(dllPathName)
91 end
92 else
93 if (InstallDir <> '') and FileExists(InstallDir + 'bin' + DirectorySeparator + FIREBIRD_CLIENT) then
94 begin
95 dllPathName := InstallDir + FIREBIRD_CLIENT;
96 IBLibrary := DoLoadLibrary(dllPathName)
97 end
98 end;
99
100 if not IsValidHandle(IBLibrary) then
101 {Use Registry key if it exists to locate library}
102 begin
103 with TRegistry.Create do
104 try
105 RootKey := HKEY_LOCAL_MACHINE;
106 if OpenKey('SOFTWARE\Firebird Project\Firebird Server\Instances',false) then
107 begin
108 if ValueExists('DefaultInstance') then
109 begin
110 InstallDir := ReadString('DefaultInstance') + 'bin' + DirectorySeparator ;
111 dllPathName := InstallDir + FIREBIRD_CLIENT;
112 IBLibrary := DoLoadLibrary(dllPathName)
113 end
114 end
115 finally
116 Free
117 end;
118
119 {Now try default install dir}
120 if not IsValidHandle(IBLibrary) then
121 begin
122 InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) +
123 DirectorySeparator + 'Firebird' +
124 DirectorySeparator + 'Firebird_3_0' +
125 DirectorySeparator + 'bin' + DirectorySeparator;
126 dllPathName := InstallDir + FIREBIRD_CLIENT;
127 IBLibrary := DoLoadLibrary(dllPathName)
128 end;
129
130 if not IsValidHandle(IBLibrary) then
131 begin
132 InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) +
133 DirectorySeparator + 'Firebird' +
134 DirectorySeparator + 'Firebird_2_5' +
135 DirectorySeparator + 'bin' + DirectorySeparator;
136 dllPathName := InstallDir + FIREBIRD_CLIENT;
137 IBLibrary := DoLoadLibrary(dllPathName)
138 end;
139
140 if not IsValidHandle(IBLibrary) then
141 begin
142 InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) +
143 DirectorySeparator + 'Firebird' +
144 DirectorySeparator + 'Firebird_2_1' +
145 DirectorySeparator + 'bin' + DirectorySeparator;
146 dllPathName := InstallDir + FIREBIRD_CLIENT;
147 IBLibrary := DoLoadLibrary(dllPathName)
148 end;
149
150 //Otherwise see if Firebird client is in path
151 //and rely on registry for location of firebird.conf and firebird.msg
152 if not IsValidHandle(IBLibrary) then
153 begin
154 IBLibrary := DoLoadLibrary(FIREBIRD_CLIENT);
155 if IBLibrary <= HINSTANCE_ERROR then
156 //well maybe InterBase is present...
157 IBLibrary := DoLoadLibrary(IBASE_DLL);
158 end;
159 end;
160 FOwnsIBLibrary := IsValidHandle(IBLibrary);
161 end;
162
163