xref: /trunk/main/xmerge/source/regutil/regutil.cpp (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*
2  * Simple Application which calls the DllRegisterServer or DllUnregisterServer functions
3  * of the XMerge ActiveSync plugin.
4  */
5 
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <windows.h>
10 
11 
12 typedef HRESULT (STDAPICALLTYPE *DLLREGISTERSERVER)(void);
13 typedef HRESULT (STDAPICALLTYPE *DLLUNREGISTERSERVER)(void);
14 
15 int main(int argc, char* argv[])
16 {
17     BOOL  bUninstall = FALSE;
18     int   nPathIndex = 1;
19 
20     if (argc < 2 || argc > 3)
21     {
22         printf("\nUsage:  regutil [/u] <Full Path of XMergeSync.dll>\n\n");
23         return -1;
24     }
25 
26 
27     if (argc == 3)
28     {
29         if (strcmp("/u", argv[1]))
30         {
31             printf("\nUnrecognised option: %s\n", argv[1]);
32             return -1;
33         }
34 
35         bUninstall = TRUE;
36         nPathIndex = 2;
37     }
38 
39 
40     // Dynamically load the library
41     HMODULE hmXMDll = LoadLibrary(argv[nPathIndex]);
42 
43     if (hmXMDll == NULL)
44     {
45         printf("\nUnable to load the library %s\n", argv[nPathIndex]);
46         return -1;
47     }
48 
49 
50     // Get an offset to the either the DllRegisterServer or DllUnregisterServer functions
51     if (!bUninstall)
52     {
53         printf("\nRegistering %s ... ", argv[nPathIndex]);
54 
55         DLLREGISTERSERVER DllRegisterServer = (DLLREGISTERSERVER)GetProcAddress(hmXMDll, "DllRegisterServer");
56 
57         if (DllRegisterServer == NULL)
58         {
59             printf("failed.\n\nDllRegisterServer is not present in library.\n");
60             return -1;
61         }
62 
63         // Now call the procedure ...
64         HRESULT regResult = DllRegisterServer() ;
65 
66         if (regResult != S_OK)
67         {
68             printf("failed.\n");
69             return -1;
70         }
71     }
72     else
73     {
74         printf("\nUnregistering %s ... ", argv[nPathIndex]);
75 
76         DLLUNREGISTERSERVER DllUnregisterServer = (DLLUNREGISTERSERVER)GetProcAddress(hmXMDll, "DllUnregisterServer");
77 
78         if (DllUnregisterServer == NULL)
79         {
80             printf("failed.\n\nDllUnregisterServer is not present in library.\n");
81             return -1;
82         }
83 
84         // Now call the procedure ...
85         HRESULT regResult = DllUnregisterServer() ;
86 
87         if (regResult != S_OK)
88         {
89             printf("failed.\n");
90             return -1;
91         }
92 
93     }
94 
95     printf("done.\n");
96 
97 
98     // Clean up
99     FreeLibrary(hmXMDll);
100 
101     return 0;
102 }