1 /* -*- Mode: C++; tab-width: 6; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla XPCOM.
17 * The Initial Developer of the Original Code is
18 * Benjamin Smedberg <benjamin@smedbergs.us>
20 * Portions created by the Initial Developer are Copyright (C) 2005
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsGlueLinking.h"
40 #include "nsXPCOMGlue.h"
42 #include "nsStringAPI.h"
54 static DependentLib
*sTop
;
55 HINSTANCE sXULLibrary
;
58 AppendDependentLib(HINSTANCE libHandle
)
60 DependentLib
*d
= new DependentLib
;
65 d
->libHandle
= libHandle
;
71 ReadDependentCB(const char *aDependentLib
)
75 LoadLibraryExW(NS_ConvertUTF8toUTF16(aDependentLib
).get(), NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
79 AppendDependentLib(h
);
82 // like strpbrk but finds the *last* char, not the first
84 ns_strrpbrk(char *string
, const char *strCharSet
)
87 for (; *string
; ++string
) {
88 for (const char *search
= strCharSet
; *search
; ++search
) {
89 if (*search
== *string
) {
91 // Since we're looking for the last char, we save "found"
92 // until we're at the end of the string.
99 // like strpbrk but finds the *last* char, not the first
101 ns_wcspbrk(wchar_t *string
, const wchar_t *strCharSet
)
103 wchar_t *found
= NULL
;
104 for (; *string
; ++string
) {
105 for (const wchar_t *search
= strCharSet
; *search
; ++search
) {
106 if (*search
== *string
) {
108 // Since we're looking for the last char, we save "found"
109 // until we're at the end of the string.
117 bool ns_isRelPath(wchar_t* path
)
130 GetFrozenFunctionsFunc
131 XPCOMGlueLoad(const char *aXpcomFile
)
133 wchar_t xpcomFile
[MAXPATHLEN
];
134 MultiByteToWideChar(CP_ACP
, 0, aXpcomFile
,-1,
135 xpcomFile
, MAXPATHLEN
);
138 if (xpcomFile
[0] == '.' && xpcomFile
[1] == '\0') {
139 wcscpy(xpcomFile
, LXPCOM_DLL
);
142 wchar_t xpcomDir
[MAXPATHLEN
];
144 if (ns_isRelPath(xpcomFile
))
146 _wfullpath(xpcomDir
, xpcomFile
, sizeof(xpcomDir
)/sizeof(wchar_t));
150 wcscpy(xpcomDir
, xpcomFile
);
152 wchar_t *lastSlash
= ns_wcspbrk(xpcomDir
, L
"/\\");
155 char xpcomDir_narrow
[MAXPATHLEN
];
156 WideCharToMultiByte(CP_ACP
, 0, xpcomDir
,-1,
157 xpcomDir_narrow
, MAX_PATH
, NULL
, NULL
);
159 XPCOMGlueLoadDependentLibs(xpcomDir_narrow
, ReadDependentCB
);
161 _snwprintf(lastSlash
, MAXPATHLEN
- wcslen(xpcomDir
), L
"\\" LXUL_DLL
);
163 LoadLibraryExW(xpcomDir
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
170 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
171 FORMAT_MESSAGE_FROM_SYSTEM
|
172 FORMAT_MESSAGE_IGNORE_INSERTS
,
175 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
180 wprintf(L
"Error loading xul.dll: %s\n", lpMsgBuf
);
186 LoadLibraryExW(xpcomFile
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
194 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
195 FORMAT_MESSAGE_FROM_SYSTEM
|
196 FORMAT_MESSAGE_IGNORE_INSERTS
,
199 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
204 wprintf(L
"Error loading xpcom.dll: %s\n", lpMsgBuf
);
209 AppendDependentLib(h
);
211 GetFrozenFunctionsFunc sym
=
212 (GetFrozenFunctionsFunc
) GetProcAddress(h
, "NS_GetFrozenFunctions");
224 FreeLibrary(sTop
->libHandle
);
226 DependentLib
*temp
= sTop
;
233 FreeLibrary(sXULLibrary
);
234 sXULLibrary
= nsnull
;
239 XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad
*symbols
)
242 return NS_ERROR_NOT_INITIALIZED
;
245 while (symbols
->functionName
) {
247 (NSFuncPtr
) GetProcAddress(sXULLibrary
, symbols
->functionName
);
248 if (!*symbols
->function
)
249 rv
= NS_ERROR_LOSS_OF_SIGNIFICANT_DATA
;