1*f8e2c85aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f8e2c85aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e2c85aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e2c85aSAndrew Rist  * distributed with this work for additional information
6*f8e2c85aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e2c85aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e2c85aSAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e2c85aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f8e2c85aSAndrew Rist  *
11*f8e2c85aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f8e2c85aSAndrew Rist  *
13*f8e2c85aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e2c85aSAndrew Rist  * software distributed under the License is distributed on an
15*f8e2c85aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e2c85aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e2c85aSAndrew Rist  * specific language governing permissions and limitations
18*f8e2c85aSAndrew Rist  * under the License.
19*f8e2c85aSAndrew Rist  *
20*f8e2c85aSAndrew Rist  *************************************************************/
21*f8e2c85aSAndrew Rist 
22*f8e2c85aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_shell.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #if defined _MSC_VER
28cdf0e10cSrcweir #pragma warning(push, 1)
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <windows.h>
31cdf0e10cSrcweir #if defined _MSC_VER
32cdf0e10cSrcweir #pragma warning(pop)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir typedef HRESULT (__stdcall *lpfnDllRegisterServer)();
36cdf0e10cSrcweir typedef HRESULT (__stdcall *lpfnDllUnregisterServer)();
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /**
39cdf0e10cSrcweir */
IsUnregisterParameter(const char * Param)40cdf0e10cSrcweir bool IsUnregisterParameter(const char* Param)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	return ((0 == _stricmp(Param, "/u")) ||
43cdf0e10cSrcweir 			(0 == _stricmp(Param, "-u")));
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /**
47cdf0e10cSrcweir */
main(int argc,char * argv[])48cdf0e10cSrcweir int main(int argc, char* argv[])
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	HMODULE hmod;
51cdf0e10cSrcweir 	HRESULT hr = E_FAIL;
52cdf0e10cSrcweir 	lpfnDllRegisterServer   lpfn_register;
53cdf0e10cSrcweir 	lpfnDllUnregisterServer lpfn_unregister;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	if (2 == argc)
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		hmod = LoadLibraryA(argv[1]);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 		if (hmod)
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			lpfn_register = (lpfnDllRegisterServer)GetProcAddress(
62cdf0e10cSrcweir 				hmod, "DllRegisterServer");
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 			if (lpfn_register)
65cdf0e10cSrcweir 				hr = lpfn_register();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 			FreeLibrary(hmod);
68cdf0e10cSrcweir 		}
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 	else if (3 == argc && IsUnregisterParameter(argv[1]))
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		hmod = LoadLibraryA(argv[2]);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		if (hmod)
75cdf0e10cSrcweir 		{
76cdf0e10cSrcweir 			lpfn_unregister = (lpfnDllUnregisterServer)GetProcAddress(
77cdf0e10cSrcweir 				hmod, "DllUnregisterServer");
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 			if (lpfn_unregister)
80cdf0e10cSrcweir 				hr = lpfn_unregister();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 			FreeLibrary(hmod);
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	return 0;
87cdf0e10cSrcweir }
88