• 动态注册OCX


    Delphi中Ocx的动态注册方法

    方法1

    uses windows;

    type
       TDllRegisterServer = function: HResult; stdcall;
      
    function RegisterOCX(FileName: string): Boolean;
    var
       OCXHand: THandle;
       RegFunc: TDllRegisterServer;
    begin
       OCXHand := LoadLibrary(PChar(FileName));
       RegFunc := GetProcAddress(OCXHand, 'DllRegisterServer');
       if @RegFunc <> nil then
         Result := RegFunc = S_OK
       else
         Result := False;
       FreeLibrary(OCXHand);
    end;

    function UnRegisterOCX(FileName: string): Boolean;
    var
       OCXHand: THandle;
       RegFunc: TDllRegisterServer;
    begin
       OCXHand := LoadLibrary(PChar(FileName));
       RegFunc := GetProcAddress(OCXHand, 'DllUnregisterServer');
       if @RegFunc <> nil then
         Result := RegFunc = S_OK
       else
         Result := False;
       FreeLibrary(OCXHand);
    end;

    方法2

    procedure TForm1.Button1Click(Sender: TObject);
    var
       astr:String;
       bstr:String;
       ProcAddr:Pointer;
       DllAddr:Integer;
    begin
       od1.Execute;
       astr:=od1.FileName+chr(0);
       DllAddr:=LoadLibrary(PChar(astr));
       if DllAddr<>0 then
         begin
           bstr:='DllregisterServer'+chr(0);
           //只要将以上处改为DllUnRegisterServer即不注册ActiveX控件
           ProcAddr:=GetProcAddress(DllAddr,PChar(bstr));
           if ProcAddr<>nil then
             CallWindowProc(ProcAddr,DllAddr,0,0,0)
           else
               ShowMessage(od1.FileName+'不是有效的控件');
           FreeLibrary(DllAddr);
         end
       else
           ShowMessage(od1.FileName+'无法装载');
    end;

    uses OLEctl {, ....};
    interface{...}
    var  OCXHandle: THandle;
    RegFunc: TDllRegisterServer;
    begin
     
    OCXHandle:= LoadLibrary('c:\XXX.ocx');
     
    RegFunc := GetProcAddress(OCXHandle, 'DllRegisterServer');
     
    if RegFunc <> 0 then ShowMessage('Error!');
     
    FreeLibrary(OCXHand);
     
    end;
     
    或者
     
    WinExec("regsvr32.exe/s yourocx.ocx",SW_NORMAL);
  • 相关阅读:
    Android:TabWidget
    Android之GridView
    Asp.Net页面生命周期
    Android笔记
    Adnroid单元测试
    GridView,ListView实例
    CSS
    C# ref,out
    有些经验是花钱都买不到的!
    数据库常用的sql语句
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1572234.html
Copyright © 2020-2023  润新知