⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regsvr.cpp

📁 regsvr32源码 WinCE X86下使用的
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include <windows.h>
#include <stdio.h>
#include <objbase.h>

typedef HRESULT (CALLBACK *LPFNINSTFUNC1)(BOOL, LPCWSTR);
        
#define MINARGS    1     // Min. # of arguments

//
//  DebugOut
//
//  printf type function for outputting debug information
//
void DebugOut( LPTSTR lpFormat, ... )
{
    TCHAR   wszOut[512];
    va_list args;

    va_start( args, lpFormat );

    _vstprintf( wszOut, lpFormat, args );

#ifdef UNDER_CE
    OutputDebugString( wszOut );
#else
    printf( TEXT("%s\n"), wszOut );
#endif
    va_end( args );
}


void PrintUsage (TCHAR *wszprogName)
{
    DebugOut (_T("Usage: %s [/u] [/n] [/i[:cmdline]] dllname\n"), wszprogName);
    DebugOut (_T("/u-\tUnregister server\n"));
    DebugOut (_T("/s-\tSilent; Display no messages\n"));
    DebugOut (_T("/i-\tCall DllInstall passing it an optional [cmdline]; when used with ") \
             _T("/u calls dll uninstall\n"));
    DebugOut (_T("/n-\tdo not call DllRegisterServer; this option must be used with /i\n"));
}

void _tmain(int argc, TCHAR **argv) 
{

    HRESULT hr;
    TCHAR *name = argv[1], *cmdline = NULL;
    unsigned char fUnreg = FALSE, fInst = FALSE, fNoreg = FALSE, fSilent = FALSE;

    CoInitializeEx(NULL, COINIT_MULTITHREADED);

    for (int index=1; argc >= (index+MINARGS); name=argv[++index])
    {
       if (_tcsnicmp (name, _T("/i"), 2) == 0) {
       
         if (_tcslen (name) > 3)
            cmdline = &(name[3]);
            
         fInst = TRUE;
       }
       
       else if (_tcsicmp (name, _T("/u")) == 0)
         fUnreg = TRUE;
         
       else if (_tcsicmp (name, _T("/n")) == 0) 
         fNoreg = TRUE;

       else if (_tcsicmp (name, _T("/s")) == 0)
         fSilent = TRUE;
         
       else if (_tcsicmp (name, _T("/?")) == 0)
       {
         PrintUsage (argv[0]);
         exit(1);
       }
         
       else
       {
         break;
       }
       
    }

    if ((argc < (index+MINARGS)) || (fNoreg && !fInst)) {
        PrintUsage (argv[0]);
        exit(1);
    }
        
    HINSTANCE hLL = LoadLibrary (name);
    if (! hLL) {
        DebugOut (_T("Could not load %s\n"), name);
        exit(1);
    }

    if (!fNoreg)
    {
        FARPROC fp = GetProcAddress (hLL,
#ifdef UNDER_CE
                        (fUnreg ? L"DllUnregisterServer" : L"DllRegisterServer"));
#else
                        (fUnreg ? "DllUnregisterServer" : "DllRegisterServer"));
#endif
        if (! fp) {
            DebugOut (_T("Registration functions are not exported from %s\n"), name);
            exit(1);
        }
    
        hr = fp();
        
        if (FAILED(hr)) {
            DebugOut(_T("Registration Operation failed hr = 0x%08x\n"), hr);
            exit(1);
        }
     }

    if (fInst)
    {
        if (cmdline && (*cmdline == _T('"')))
        {
            WORD wLen = _tcslen (cmdline);
            if (cmdline[wLen-1] == _T('"'))
                cmdline[wLen-1] = _T('\0');
                
            cmdline++;
         }
         
#ifdef UNDER_CE    
        LPFNINSTFUNC1 fpInst = (LPFNINSTFUNC1) GetProcAddress (hLL, L"DllInstall");
#else
        LPFNINSTFUNC1 fpInst = (LPFNINSTFUNC1) GetProcAddress (hLL, "DllInstall");
#endif
        if (! fpInst) {
            DebugOut (_T("DllInstall is not exported from %s\n"), name);
            exit(1);
        }

#ifdef UNICODE
        hr = fpInst( (fUnreg ? FALSE : TRUE), cmdline);
#else
        hr = fpInst( (fUnreg ? FALSE : TRUE), uxdup (cmdline));
#endif

        if (FAILED(hr)) {
            DebugOut (_T("DllInstall failed hr = 0x%08x"), hr);
            exit(1);
        }
    }

    if (!fSilent)
    {
        if (!fNoreg)
        {
            DebugOut (_T("%s"), (fUnreg ? _T("DllUnregisterServer") : _T("DllRegisterServer")));
            if (fInst) DebugOut (_T(" and "));
        }

        if (fInst) DebugOut (_T("DllInstall"));

        DebugOut (_T(" in %s succeeded.\n"), name);
     }

    CoUninitialize();

    exit(0);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -