1*800f9471SAndrew Rist /**************************************************************
2*800f9471SAndrew Rist *
3*800f9471SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*800f9471SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*800f9471SAndrew Rist * distributed with this work for additional information
6*800f9471SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*800f9471SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*800f9471SAndrew Rist * "License"); you may not use this file except in compliance
9*800f9471SAndrew Rist * with the License. You may obtain a copy of the License at
10*800f9471SAndrew Rist *
11*800f9471SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*800f9471SAndrew Rist *
13*800f9471SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*800f9471SAndrew Rist * software distributed under the License is distributed on an
15*800f9471SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*800f9471SAndrew Rist * KIND, either express or implied. See the License for the
17*800f9471SAndrew Rist * specific language governing permissions and limitations
18*800f9471SAndrew Rist * under the License.
19*800f9471SAndrew Rist *
20*800f9471SAndrew Rist *************************************************************/
21*800f9471SAndrew Rist
22cdf0e10cSrcweir /*
23cdf0e10cSrcweir * Simple Application which calls the DllRegisterServer or DllUnregisterServer functions
24cdf0e10cSrcweir * of the XMerge ActiveSync plugin.
25cdf0e10cSrcweir */
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir #include <string.h>
30cdf0e10cSrcweir #include <windows.h>
31cdf0e10cSrcweir
32cdf0e10cSrcweir
33cdf0e10cSrcweir typedef HRESULT (STDAPICALLTYPE *DLLREGISTERSERVER)(void);
34cdf0e10cSrcweir typedef HRESULT (STDAPICALLTYPE *DLLUNREGISTERSERVER)(void);
35cdf0e10cSrcweir
main(int argc,char * argv[])36cdf0e10cSrcweir int main(int argc, char* argv[])
37cdf0e10cSrcweir {
38cdf0e10cSrcweir BOOL bUninstall = FALSE;
39cdf0e10cSrcweir int nPathIndex = 1;
40cdf0e10cSrcweir
41cdf0e10cSrcweir if (argc < 2 || argc > 3)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir printf("\nUsage: regutil [/u] <Full Path of XMergeSync.dll>\n\n");
44cdf0e10cSrcweir return -1;
45cdf0e10cSrcweir }
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir if (argc == 3)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir if (strcmp("/u", argv[1]))
51cdf0e10cSrcweir {
52cdf0e10cSrcweir printf("\nUnrecognised option: %s\n", argv[1]);
53cdf0e10cSrcweir return -1;
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
56cdf0e10cSrcweir bUninstall = TRUE;
57cdf0e10cSrcweir nPathIndex = 2;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
60cdf0e10cSrcweir
61cdf0e10cSrcweir // Dynamically load the library
62cdf0e10cSrcweir HMODULE hmXMDll = LoadLibrary(argv[nPathIndex]);
63cdf0e10cSrcweir
64cdf0e10cSrcweir if (hmXMDll == NULL)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir printf("\nUnable to load the library %s\n", argv[nPathIndex]);
67cdf0e10cSrcweir return -1;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
70cdf0e10cSrcweir
71cdf0e10cSrcweir // Get an offset to the either the DllRegisterServer or DllUnregisterServer functions
72cdf0e10cSrcweir if (!bUninstall)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir printf("\nRegistering %s ... ", argv[nPathIndex]);
75cdf0e10cSrcweir
76cdf0e10cSrcweir DLLREGISTERSERVER DllRegisterServer = (DLLREGISTERSERVER)GetProcAddress(hmXMDll, "DllRegisterServer");
77cdf0e10cSrcweir
78cdf0e10cSrcweir if (DllRegisterServer == NULL)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir printf("failed.\n\nDllRegisterServer is not present in library.\n");
81cdf0e10cSrcweir return -1;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir // Now call the procedure ...
85cdf0e10cSrcweir HRESULT regResult = DllRegisterServer() ;
86cdf0e10cSrcweir
87cdf0e10cSrcweir if (regResult != S_OK)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir printf("failed.\n");
90cdf0e10cSrcweir return -1;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir }
93cdf0e10cSrcweir else
94cdf0e10cSrcweir {
95cdf0e10cSrcweir printf("\nUnregistering %s ... ", argv[nPathIndex]);
96cdf0e10cSrcweir
97cdf0e10cSrcweir DLLUNREGISTERSERVER DllUnregisterServer = (DLLUNREGISTERSERVER)GetProcAddress(hmXMDll, "DllUnregisterServer");
98cdf0e10cSrcweir
99cdf0e10cSrcweir if (DllUnregisterServer == NULL)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir printf("failed.\n\nDllUnregisterServer is not present in library.\n");
102cdf0e10cSrcweir return -1;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir // Now call the procedure ...
106cdf0e10cSrcweir HRESULT regResult = DllUnregisterServer() ;
107cdf0e10cSrcweir
108cdf0e10cSrcweir if (regResult != S_OK)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir printf("failed.\n");
111cdf0e10cSrcweir return -1;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir printf("done.\n");
117cdf0e10cSrcweir
118cdf0e10cSrcweir
119cdf0e10cSrcweir // Clean up
120cdf0e10cSrcweir FreeLibrary(hmXMDll);
121cdf0e10cSrcweir
122cdf0e10cSrcweir return 0;
123cdf0e10cSrcweir }