gecko-dev/cmd/wincom/dllreg/dllreg.c

181 строка
4.6 KiB
C
Исходник Обычный вид История

1998-03-28 05:44:41 +03:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
1998-03-28 05:44:41 +03:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
1998-03-28 05:44:41 +03:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-03-28 05:44:41 +03:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-03-28 05:44:41 +03:00
*/
#ifdef WIN32
#include <objbase.h>
#else
#include <windows.h>
#include <compobj.h>
#include <stdlib.h>
#endif
/* This is mainly sample source to show how to auto[un]register a DLL.
* This is equivalent to REGSVR32.EXE for 32 bits (VC4), and
* REGSVR.EXE for 16 bits (MSVC CDK16 only).
*
* Also, we can ship this, I am not sure if we can redistribute those
* utilities.
*/
typedef HRESULT (*DllServerFunction)(void);
#ifdef WIN32
int main(int iArgc, char *paArgv[])
#else
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#endif
{
BOOL bRegister = TRUE;
BOOL bRetval = FALSE;
char szPath[_MAX_PATH];
LPSTR pLib = NULL;
LPSTR pOldLib = NULL;
#ifdef WIN32
if(iArgc >= 2) {
int iTraverse = 1;
while(iTraverse < iArgc) {
if(!stricmp(paArgv[iTraverse], "/u")) {
bRegister = FALSE;
}
else {
pLib = paArgv[iTraverse];
}
iTraverse++;
}
}
#else
if(lpCmdLine && *lpCmdLine) {
char *pTraverse = lpCmdLine;
while(*pTraverse) {
if(!strnicmp(pTraverse, "/u", 2)) {
bRegister = FALSE;
*pTraverse = ' ';
pTraverse++;
*pTraverse = ' ';
}
pTraverse++;
}
pTraverse = lpCmdLine;
while(*pTraverse && isspace(*pTraverse)) {
pTraverse++;
}
pLib = pTraverse;
}
#endif
CoInitialize(NULL);
if(pLib) {
/* Expand to the full path or LoadLibrary likes to fail
* if it is too convoluted/long/relative.
*/
pOldLib = pLib;
pLib = _fullpath(szPath, pLib, sizeof(szPath));
}
if(pLib) {
HINSTANCE hLibInstance = hLibInstance = LoadLibrary(pLib);
#ifdef WIN32
if(hLibInstance)
#else
if(hLibInstance > (HINSTANCE)HINSTANCE_ERROR)
#endif
{
DllServerFunction RegistryFunc = NULL;
if(bRegister) {
(FARPROC)RegistryFunc = GetProcAddress(hLibInstance, "DllRegisterServer");
}
else {
(FARPROC)RegistryFunc = GetProcAddress(hLibInstance, "DllUnregisterServer");
}
if(RegistryFunc) {
HRESULT hResult = (RegistryFunc)();
if(GetScode(hResult) == S_OK) {
bRetval = TRUE;
}
RegistryFunc = NULL;
}
else {
/* If the DLL doesn't have those functions then it just doesn't support
* self-registration. We don't consider that to be an error
*
* We should consider checking for the "OleSelfRegister" string in the
* StringFileInfo section of the version information resource. If the DLL
* has "OleSelfRegister" but doesn't have the self-registration functions
* then that would be an error
*/
bRetval = TRUE;
}
FreeLibrary(hLibInstance);
hLibInstance = NULL;
}
}
CoUninitialize();
if(bRetval == FALSE) {
char *pMessage;
if(bRegister == TRUE) {
pMessage = "Registration did not succeed.";
}
else {
pMessage = "Unregistration did not succeed.";
}
if(pLib == NULL) {
pLib = "Usage";
pMessage = "dllreg [/u] filename.dll";
}
#ifndef DEBUG_blythe
#ifdef WIN32
printf("%s:\t%s\n", pLib, pMessage);
#else
MessageBox(NULL, pMessage, pLib, MB_OK);
#endif
#endif
}
if(pLib) {
pLib = pOldLib;
}
#ifdef WIN32
return(bRetval == FALSE);
#else
return(0);
#endif
}