uses ShellAPI;

function ExecAndWait(const ExecuteFile, ParamString : string): boolean;
var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
begin
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(ExecuteFile);
lpParameters := PChar(ParamString);
nShow := SW_HIDE;
end;
if ShellExecuteEx(@SEInfo) then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
Result:=True;
end
else Result:=False;
end; procedure RegisterOCX;
type
TRegFunc = function : HResult; stdcall;
var
ARegFunc : TRegFunc;
aHandle : THandle;
ocxPath : string;
begin
try
ocxPath :='E:\SVN\Matrix控件\JydMax.ocx' ;//ExtractFilePath(Application.ExeName) + 'Flash.ocx';
aHandle := LoadLibrary(PChar(ocxPath));
if aHandle <> 0 then
begin
ARegFunc := GetProcAddress(aHandle,'DllRegisterServer');
if Assigned(ARegFunc) then
begin
ExecAndWait('regsvr32','/s ' + ocxPath);
end;
FreeLibrary(aHandle);
end;
except
ShowMessage(Format('Unable to register %s', [ocxPath]));
end;
end;

  

{1.}

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.} function RegisterServer(const aDllFileName: string; aRegister: Boolean): Boolean;
type
TRegProc = function: HResult;
stdcall;
const
cRegFuncNameArr: array [Boolean] of PChar =
('DllUnregisterServer', 'DllRegisterServer');
var
vLibHandle: THandle;
vRegProc: TRegProc;
begin
Result := False;
vLibHandle := LoadLibrary(PChar(aDllFileName));
if vLibHandle = 0 then Exit;
@vRegProc := GetProcAddress(vLibHandle, cRegFuncNameArr[aRegister]);
if @vRegProc <> nil then
Result := vRegProc = S_OK;
FreeLibrary(vLibHandle);
end;

  

delphi注册/反注册OCX的更多相关文章

  1. 【Demo 0025】注册/反注册窗体类RegisterClassEx/UnregisterClass

    所有窗体在创建前都必须注册窗体类,只有注册的窗体类才被系统认知并允许实例化,换句话说通过注册告诉进程窗体管理器此类窗体的属性如: 背景色,窗体上的鼠标样式以及窗体事件处理函数等;  有一些控件类系统自 ...

  2. dll的注册与反注册

    regsvr32.exe是32位系统下使用的DLL注册和反注册工具,使用它必须通过命令行的方式使用,格式是:regsvr32 [/i[:cmdline]] DLL文件名命令可以在"开始→运行 ...

  3. ActiveX控件的注册和反注册

    原文转自 https://blog.csdn.net/piaopiaopiaopiaopiao/article/details/41649495 ActiveX控件,需要注册之后才能使用. 注意:注册 ...

  4. VC++如何在程序中用代码注册和卸载ocx控件(代码)

    方法一:在dos或Windows命令行下运行:regsvr32 ocxname.ocx 注册 示例:regsvr32 netshare.ocx     //注册netshare.ocx控件regsvr ...

  5. springcloud 服务注册、反注册 AOP 拦截,实现自定义功能

    @Aspect@Component@Order(1000)public class EurekaServerAspect {private Logger logger = Logger.getLogg ...

  6. Android BroadcastReceiver 注册和反注册

    说起来这个问题很简单,只要注册和反注册成对出现就行,好像很多教材都是如此介绍.但实际开发中,对广播注册和反注册的时机把握还是很重要的. 关于广BroadcastReceiver注册和反注册时机,主要有 ...

  7. 7.Go退出向Consuk反注册服务,优雅关闭服务

    注册和反注册代码 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ...

  8. [C#反编译教程]001.Reflector.NET反编译工具 v8.5绿色版+注册机+注册教程

    截图 下载地址 Reflector.NET反编译工具 v8.5绿色版+注册机 下载地址:http://pan.baidu.com/s/1mgN1Cpi 密码:mx19 简介 .NET Reflecto ...

  9. RedGate .NET Reflector注册问题(反注册)

    Reflector分为桌面版和VS集成版本,当我们使用注册机注册的时候如果注册了Standvard版本,那么我们的VS就不能集成查看,也不能Debug,那么这 显然不是我们想要的,我们会选择重新注册, ...

随机推荐

  1. Selenium2学习-007-WebUI自动化实战实例-005-解决 Firefox 版本不兼容:org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary

    此文主要讲述 Java 运行 Selenium 脚本时,因 Friefox 浏览器版本与 selenium-server-standalone-x.xx.x.jar 不兼容引起的 org.openqa ...

  2. SQLServer Note

    1. Grant necessory permission to user account, so it can use SQL profiler. USE masterGRANT ALTER TRA ...

  3. python基础篇-day1

    python基础篇 python是由C语言写的: pass 占位符: del,python中全局的功能,删除内存中的数据: 变量赋值的方法: user,pass = 'freddy','freddy1 ...

  4. Shell函数语法

    Shell函数语法 定义函数: function   函数名(){ 指令... } 调用函数,方法1: 函数名 调用函数,方法2: 函数名  参数一   参数二 return在函数里面使用会跳出函数并 ...

  5. iOS:后台定位并实时向服务器发送位置

    第一步:开启后台模式,选中定位,选择project --> capabilities-->Backgorund Modes --> Location updates 如图: 第二步: ...

  6. ICP算法使用遇到的问题

    这几天在学习数据关联的方法,本来想使用ICP算法进行距离测距数据的配准,但是用的过程中出现问题,配的不准,而且偏差更大了. 红色的和黄色的2维激光点进行ICP配准,但将变换矩阵和黄色进行乘之后偏差更大 ...

  7. Web开发学习

    这几天天天学习网络开发的一些东西,接触了好些概念.原本打算自己弄个个人博客,BlogEngine.net已经做的很好了,可以直接拿来用而且源码开放.做的很不错,是WebForm的.本来打算好好学习一下 ...

  8. MySQLdb模块 类操作方法

    #!/usr/bin/env python #-*- coding:utf- -*- from day5 import conf import MySQLdb class MysqlHepler(ob ...

  9. .NET Framework 4 中的并行编程9---线程安全集合类

    原文转载自:http://www.cnblogs.com/xray2005/archive/2011/10/11/2206745.html 在.Net 4中,新增System.Collections. ...

  10. linux 硬件信息

    1. 查看物理CPU的个数 #cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 2. 查看逻辑CPU的个数 #cat / ...