merge the formfield patch from ooo-build
[ooovba.git] / shell / source / win32 / shlxthandler / ooofilt / proxy / ooofiltproxy.cxx
blobb3bbe22964fd84d975f949f9a1dd9f31ce017b48
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ooofiltproxy.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
34 #if defined _MSC_VER
35 #pragma warning(push, 1)
36 #endif
37 #include <windows.h>
38 #if defined _MSC_VER
39 #pragma warning(pop)
40 #endif
41 #include <tchar.h>
42 #ifdef __MINGW32__
43 #include <basetyps.h>
44 #endif
48 The indexing filter library ooofilt.dll is linked against a couple
49 of libaries (e.g. stlport, uwinapi, ...) which are not standard on
50 a windows system. Unfortunately the library will be loaded by the
51 indexing service via LoadLibrary so that the libraries ooofilt.dll
52 depends on need to be in one of the standard search directories or
53 the <office installation> directory need to be added to the PATH
54 environment variable. In order to prevent failures while loading
55 the ooofilt.dll we're installing and registering this proxy library
56 which will load ooofilt.dll using LoadLibraryEx with the flag
57 LOAD_WITH_ALTERED_SEARCH_PATH (see MSDN for details). This approach
58 ensures that all libraries ooofilt.dll depends on will be found.
61 typedef HRESULT (__stdcall * Forward_DllGetClassObject_t)(REFCLSID cid, REFIID iid, void** ppvObj);
62 typedef HRESULT (__stdcall * Forward_DllCanUnloadNow_t)();
63 typedef HRESULT (__stdcall * Forward_DllRegisterServer_t)();
64 typedef HRESULT (__stdcall * Forward_DllUnregisterServer_t)();
66 Forward_DllGetClassObject_t Forward_DllGetClassObject = NULL;
67 Forward_DllCanUnloadNow_t Forward_DllCanUnloadNow = NULL;
68 Forward_DllRegisterServer_t Forward_DllRegisterServer = NULL;
69 Forward_DllUnregisterServer_t Forward_DllUnregisterServer = NULL;
71 HMODULE hOoofilt = NULL;
72 HMODULE hThisLibrary = NULL;
74 /* Truncates the file name from an absolute path but
75 leaves the final '\' */
76 void PathTruncateFileName(TCHAR* path)
78 TCHAR* p = path + lstrlen(path);
79 while (*p != _T('\\')) p--;
80 p++;
81 *p = 0;
84 void Init()
86 if (Forward_DllGetClassObject == NULL)
88 TCHAR buff[MAX_PATH];
89 GetModuleFileName(hThisLibrary, buff, (sizeof(buff)/sizeof(TCHAR)));
90 PathTruncateFileName(buff);
91 lstrcat(buff, TEXT("ooofilt.dll"));
93 hOoofilt = LoadLibraryEx(buff, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
95 if (hOoofilt)
97 Forward_DllGetClassObject = reinterpret_cast<Forward_DllGetClassObject_t>(
98 GetProcAddress(hOoofilt, "DllGetClassObject"));
99 Forward_DllCanUnloadNow = reinterpret_cast<Forward_DllCanUnloadNow_t>(
100 GetProcAddress(hOoofilt, "DllCanUnloadNow"));
101 Forward_DllRegisterServer = reinterpret_cast<Forward_DllRegisterServer_t>(
102 GetProcAddress(hOoofilt, "DllRegisterServer"));
103 Forward_DllUnregisterServer = reinterpret_cast<Forward_DllUnregisterServer_t>(
104 GetProcAddress(hOoofilt, "DllUnregisterServer"));
109 extern "C" BOOL WINAPI DllMain(HMODULE hInstance, DWORD fdwReason, LPVOID /*lpvReserved*/)
111 switch (fdwReason)
113 case DLL_PROCESS_ATTACH:
114 DisableThreadLibraryCalls( hInstance );
115 hThisLibrary = hInstance;
116 break;
117 case DLL_PROCESS_DETACH:
118 if (hOoofilt)
119 FreeLibrary(hOoofilt);
120 break;
121 default:
122 break;
124 return TRUE;
127 extern "C" HRESULT __stdcall DllGetClassObject(REFCLSID cid, REFIID iid, void** ppvObj)
129 Init();
131 if (Forward_DllGetClassObject)
132 return Forward_DllGetClassObject(cid, iid, ppvObj);
133 else
134 return E_FAIL;
137 extern "C" HRESULT __stdcall DllCanUnloadNow()
139 Init();
141 if (Forward_DllCanUnloadNow)
142 return Forward_DllCanUnloadNow();
143 else
144 return E_FAIL;
147 extern "C" HRESULT __stdcall DllRegisterServer()
149 Init();
150 if (Forward_DllRegisterServer)
151 return Forward_DllRegisterServer();
152 else
153 return E_FAIL;
156 extern "C" HRESULT __stdcall DllUnregisterServer()
158 Init();
160 if (Forward_DllUnregisterServer)
161 return Forward_DllUnregisterServer();
162 else
163 return E_FAIL;