| 1 | /*
|
|---|
| 2 | *
|
|---|
| 3 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 4 | *
|
|---|
| 5 | */
|
|---|
| 6 | /*
|
|---|
| 7 | * RegSvr32 for OS/2
|
|---|
| 8 | *
|
|---|
| 9 | * 1/9/99
|
|---|
| 10 | *
|
|---|
| 11 | * Copyright 1999 David J. Raison
|
|---|
| 12 | *
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | #include "ole32.h"
|
|---|
| 16 | #include <stdarg.h>
|
|---|
| 17 | #include <ctype.h>
|
|---|
| 18 |
|
|---|
| 19 | // ======================================================================
|
|---|
| 20 | // Local Data
|
|---|
| 21 | // ======================================================================
|
|---|
| 22 | static int fRegister = 1;
|
|---|
| 23 | static int fSilent = 0;
|
|---|
| 24 | static char szFile[1024];
|
|---|
| 25 | static HANDLE hdlObject;
|
|---|
| 26 |
|
|---|
| 27 | // ======================================================================
|
|---|
| 28 | // Prototypes.
|
|---|
| 29 | // ======================================================================
|
|---|
| 30 | extern HRESULT WIN32API OleInitialize(LPVOID reserved);
|
|---|
| 31 | extern HRESULT WIN32API OleUninitialize(void);
|
|---|
| 32 |
|
|---|
| 33 | static HRESULT parse_command(int argc, char * argv[]);
|
|---|
| 34 | static HRESULT load_object(void);
|
|---|
| 35 | static HRESULT register_object(void);
|
|---|
| 36 | static HRESULT deregister_object(void);
|
|---|
| 37 | static HRESULT unload_object(void);
|
|---|
| 38 | static HRESULT sign_on(void);
|
|---|
| 39 | static HRESULT sign_off(void);
|
|---|
| 40 | static HRESULT report_msg(char * fmt, ...);
|
|---|
| 41 | static HRESULT report_err(HRESULT hr, char * fmt, ...);
|
|---|
| 42 | static HRESULT usage(char * fmt, ...);
|
|---|
| 43 |
|
|---|
| 44 | // ======================================================================
|
|---|
| 45 | // Public API's
|
|---|
| 46 | // ======================================================================
|
|---|
| 47 | extern int main(int argc, char * argv[])
|
|---|
| 48 | {
|
|---|
| 49 | HRESULT hr;
|
|---|
| 50 |
|
|---|
| 51 | if((hr = sign_on()) != S_OK)
|
|---|
| 52 | return hr;
|
|---|
| 53 |
|
|---|
| 54 | if((hr = parse_command(argc, argv)) != S_OK)
|
|---|
| 55 | return hr;
|
|---|
| 56 |
|
|---|
| 57 | if((hr = load_object()) != S_OK)
|
|---|
| 58 | return hr;
|
|---|
| 59 |
|
|---|
| 60 | if (fRegister)
|
|---|
| 61 | hr = register_object();
|
|---|
| 62 | else
|
|---|
| 63 | hr = deregister_object();
|
|---|
| 64 |
|
|---|
| 65 | if (hr != S_OK)
|
|---|
| 66 | return hr;
|
|---|
| 67 |
|
|---|
| 68 | if((hr = unload_object()) != S_OK)
|
|---|
| 69 | return hr;
|
|---|
| 70 |
|
|---|
| 71 | return sign_off();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // ======================================================================
|
|---|
| 75 | // Private functions.
|
|---|
| 76 | // ======================================================================
|
|---|
| 77 |
|
|---|
| 78 | // ----------------------------------------------------------------------
|
|---|
| 79 | // sign_on
|
|---|
| 80 | // ----------------------------------------------------------------------
|
|---|
| 81 | static HRESULT sign_on(void)
|
|---|
| 82 | {
|
|---|
| 83 | HRESULT hr;
|
|---|
| 84 |
|
|---|
| 85 | hr = OleInitialize(NULL);
|
|---|
| 86 | if (hr != S_OK)
|
|---|
| 87 | return report_err(hr, "Error initialising OLE");
|
|---|
| 88 |
|
|---|
| 89 | return S_OK;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | // ----------------------------------------------------------------------
|
|---|
| 93 | // sign_off
|
|---|
| 94 | // ----------------------------------------------------------------------
|
|---|
| 95 | static HRESULT sign_off(void)
|
|---|
| 96 | {
|
|---|
| 97 | OleUninitialize();
|
|---|
| 98 | return report_msg("%s initialised OK", szFile);
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | // ----------------------------------------------------------------------
|
|---|
| 102 | // parse_command
|
|---|
| 103 | // ----------------------------------------------------------------------
|
|---|
| 104 | static HRESULT parse_command(int argc, char * argv[])
|
|---|
| 105 | {
|
|---|
| 106 | int ii;
|
|---|
| 107 | char * pArg;
|
|---|
| 108 |
|
|---|
| 109 | // Initial conditions.
|
|---|
| 110 | fRegister = 1;
|
|---|
| 111 | fSilent = 0;
|
|---|
| 112 | szFile[0] = 0;
|
|---|
| 113 |
|
|---|
| 114 | // Loop through args...
|
|---|
| 115 | for (ii = 1; ii < argc; ii++)
|
|---|
| 116 | {
|
|---|
| 117 | pArg = argv[ii];
|
|---|
| 118 |
|
|---|
| 119 | if ((pArg[0] == '-') || (pArg[0] == '/'))
|
|---|
| 120 | {
|
|---|
| 121 | switch(toupper(pArg[1]))
|
|---|
| 122 | {
|
|---|
| 123 | case 'S':
|
|---|
| 124 | {
|
|---|
| 125 | fSilent = 1;
|
|---|
| 126 | break;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | case 'U':
|
|---|
| 130 | {
|
|---|
| 131 | fRegister = 0;
|
|---|
| 132 | break;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | default:
|
|---|
| 136 | {
|
|---|
| 137 | return usage("Unknown switch '%c'", pArg[1] );
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | else if (strlen(szFile) == 0)
|
|---|
| 142 | {
|
|---|
| 143 | strcpy(szFile, pArg);
|
|---|
| 144 | }
|
|---|
| 145 | else
|
|---|
| 146 | {
|
|---|
| 147 | return usage("Too many files specified");
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | if (strlen(szFile) == 0)
|
|---|
| 151 | return usage("No file specified");
|
|---|
| 152 |
|
|---|
| 153 | return S_OK;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | // ----------------------------------------------------------------------
|
|---|
| 157 | // load_object
|
|---|
| 158 | // ----------------------------------------------------------------------
|
|---|
| 159 | static HRESULT load_object(void)
|
|---|
| 160 | {
|
|---|
| 161 | hdlObject = CoLoadLibrary(szFile, 1);
|
|---|
| 162 | if (hdlObject == 0)
|
|---|
| 163 | return report_err(S_FALSE, "Failed to load '%s'", szFile);
|
|---|
| 164 |
|
|---|
| 165 | return S_OK;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | // ----------------------------------------------------------------------
|
|---|
| 169 | // register_object
|
|---|
| 170 | // ----------------------------------------------------------------------
|
|---|
| 171 | static HRESULT register_object(void)
|
|---|
| 172 | {
|
|---|
| 173 | typedef HRESULT(*LPFNREGISTER)(void);
|
|---|
| 174 |
|
|---|
| 175 | LPFNREGISTER pfnRegister;
|
|---|
| 176 | HRESULT hr;
|
|---|
| 177 |
|
|---|
| 178 | pfnRegister = (LPFNREGISTER)GetProcAddress(hdlObject, "DllRegisterServer");
|
|---|
| 179 |
|
|---|
| 180 | if (pfnRegister == NULL)
|
|---|
| 181 | return report_err(S_FALSE, "Unable to locate registration entry point in '%s'", szFile);
|
|---|
| 182 |
|
|---|
| 183 | hr = pfnRegister();
|
|---|
| 184 | if (hr != S_OK)
|
|---|
| 185 | return report_err(hr, "Registration for '%s' returned error 0x%08lx", szFile, hr);
|
|---|
| 186 |
|
|---|
| 187 | return S_OK;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | // ----------------------------------------------------------------------
|
|---|
| 191 | // deregister_object
|
|---|
| 192 | // ----------------------------------------------------------------------
|
|---|
| 193 | static HRESULT deregister_object(void)
|
|---|
| 194 | {
|
|---|
| 195 | typedef HRESULT(*LPFNUNREGISTER)(void);
|
|---|
| 196 |
|
|---|
| 197 | LPFNUNREGISTER pfnUnregister;
|
|---|
| 198 | HRESULT hr;
|
|---|
| 199 |
|
|---|
| 200 | pfnUnregister = (LPFNUNREGISTER)GetProcAddress(hdlObject, "DllUnregisterServer");
|
|---|
| 201 |
|
|---|
| 202 | if (pfnUnregister == NULL)
|
|---|
| 203 | return report_err(S_FALSE, "Unable to locate unregistration entry point in '%s'", szFile);
|
|---|
| 204 |
|
|---|
| 205 | hr = pfnUnregister();
|
|---|
| 206 | if (hr != S_OK)
|
|---|
| 207 | return report_err(hr, "Unregistration for '%s' returned error 0x%08lx", szFile, hr);
|
|---|
| 208 |
|
|---|
| 209 | return S_OK;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | // ----------------------------------------------------------------------
|
|---|
| 213 | // unload_object
|
|---|
| 214 | // ----------------------------------------------------------------------
|
|---|
| 215 | static HRESULT unload_object(void)
|
|---|
| 216 | {
|
|---|
| 217 | CoFreeLibrary(hdlObject);
|
|---|
| 218 | return S_OK;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | // ----------------------------------------------------------------------
|
|---|
| 222 | // report_msg
|
|---|
| 223 | // ----------------------------------------------------------------------
|
|---|
| 224 | static HRESULT report_msg(char * fmt, ...)
|
|---|
| 225 | {
|
|---|
| 226 | if (!fSilent)
|
|---|
| 227 | {
|
|---|
| 228 | va_list va_ptr;
|
|---|
| 229 | HWND hwnd = GetDesktopWindow();
|
|---|
| 230 | char text[1024];
|
|---|
| 231 |
|
|---|
| 232 | va_start(va_ptr, fmt);
|
|---|
| 233 | vsprintf(text, fmt, va_ptr);
|
|---|
| 234 | va_end(va_ptr);
|
|---|
| 235 |
|
|---|
| 236 | MessageBoxA(hwnd, text, "RegSvr32", MB_OK | MB_ICONINFORMATION);
|
|---|
| 237 | }
|
|---|
| 238 | return S_OK;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | // ----------------------------------------------------------------------
|
|---|
| 242 | // report_err
|
|---|
| 243 | // ----------------------------------------------------------------------
|
|---|
| 244 | static HRESULT report_err(HRESULT hr, char * fmt, ...)
|
|---|
| 245 | {
|
|---|
| 246 | va_list va_ptr;
|
|---|
| 247 | HWND hwnd = GetDesktopWindow();
|
|---|
| 248 | char text[1024];
|
|---|
| 249 |
|
|---|
| 250 | va_start(va_ptr, fmt);
|
|---|
| 251 | vsprintf(text, fmt, va_ptr);
|
|---|
| 252 | va_end(va_ptr);
|
|---|
| 253 |
|
|---|
| 254 | MessageBoxA(hwnd, text, "RegSvr32", MB_OK | MB_ICONERROR);
|
|---|
| 255 |
|
|---|
| 256 | return hr;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | // ----------------------------------------------------------------------
|
|---|
| 260 | // usage
|
|---|
| 261 | // ----------------------------------------------------------------------
|
|---|
| 262 | static HRESULT usage(char * fmt, ...)
|
|---|
| 263 | {
|
|---|
| 264 | va_list va_ptr;
|
|---|
| 265 | HWND hwnd = GetDesktopWindow();
|
|---|
| 266 | char text[256];
|
|---|
| 267 | char msg[1024];
|
|---|
| 268 |
|
|---|
| 269 | va_start(va_ptr, fmt);
|
|---|
| 270 | vsprintf(text, fmt, va_ptr);
|
|---|
| 271 | va_end(va_ptr);
|
|---|
| 272 | sprintf(msg, "Error - %s\n\n"
|
|---|
| 273 | "Usage:\n"
|
|---|
| 274 | "regsvr32 [/s] [/u] filename\n"
|
|---|
| 275 | "where\n"
|
|---|
| 276 | "/s - silent completion\n"
|
|---|
| 277 | "/u - unregister", text);
|
|---|
| 278 |
|
|---|
| 279 | MessageBoxA(hwnd, msg, "RegSvr32", MB_OK | MB_ICONWARNING);
|
|---|
| 280 |
|
|---|
| 281 | return S_FALSE;
|
|---|
| 282 | }
|
|---|