• 通过代码注册COM、DLL组件


      注册代码如下:

     C++ Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    //
    //=================================================//
    //If returns    Zero, DLL successfully registered...
    //        -2 means DLL can not be loaded..
    //        -3 means DLL Entry point can not be found..
    //        -4 means Could not register the file... 
    //                 DLL Registration failed..
    //================================================//
    int RegisterComponent(char *absPath)
    {
        HINSTANCE hDLL = LoadLibrary(absPath);
        
    if(hDLL == NULL)
        {
            
    //-2 means DLL can not be loaded..
            return -2;            
        }

        
    typedef HRESULT (CALLBACK *HCRET)(void);
        HCRET lpfnDllRegisterServer;
        lpfnDllRegisterServer = 
             (HCRET)GetProcAddress(hDLL, 
    "DllRegisterServer");

        
    if(lpfnDllRegisterServer == NULL)
        {
            
    //-3 means DLL Entry point can not be found..
            return -3;            
        }

        
    //Call the function by function pointer..
        if(FAILED((*lpfnDllRegisterServer)()))            
        {
            
    //-4 means Could not register the file... 
            //DLL Registration failed..
            return -4;            
        }
        
    return 0;
    }
    //

      测试代码:

     C++ Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    //
    int nVal = RegisterComponent("C:\KvDateTime.OCX");
    if(nVal == 0)
    {
        AfxMessageBox(
    "Component Successfully Registered...");
    }
    else if(nVal == -2)
    {
        AfxMessageBox(
    "DLL can not be loaded.. Reason could "
           
    "be path is incorrect or.. Component is corrupt");
    }
    else if(nVal == -3)
    {
        AfxMessageBox(
    "DLL Entrypoint for function "
                     
    "DLLRegisterServer could not be found..");
    }
    else if(nVal == -4)
    {
        AfxMessageBox(
    "DLL Registration Failed..");
    }
    else
    {
        AfxMessageBox(
    "Unknown error in registering the file..");
    }
    //
  • 相关阅读:
    Web.config Transformation Syntax for Web Application Project Deployment
    xcode 8.1 (8B62)真机调试配置
    主机与虚拟机互ping
    mac系统下安装mysql步骤
    iphone设备尺寸规格
    linux环境下oracle静默安装
    实现静默安装APK的方法
    mac系统下如何删除银行安全插件
    mac系统下设置eclipse的补全快捷键方法
    给Xcode增加复制行、删除行快捷键的方法
  • 原文地址:https://www.cnblogs.com/MakeView660/p/8446579.html
Copyright © 2020-2023  润新知