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