程序运行时自动注册OCX或DLL

samool 发布暂无评论8822 阅读

AI摘要

本文介绍了如何在程序运行时自动注册OCX或DLL文件。示例代码使用Delphi语言,首先检查OCX文件是否存在,然后加载库并获取注册函数,调用该函数完成注册。如果注册失败,程序会显示错误消息并终止。最后,程序创建并运行主窗体。

[php]
program RegOcxSample;

uses
  Forms,
  SysUtils,
  Dialogs,
  ActiveX,
  Windows,
  Unit1 in 'Unit1.pas' {Frm_Main};

{$R *.res}
var
  OCXHand:THandle;
  RegFunc:TDLLRegisterServer;
  sfile:string;
begin
  Application.Initialize;

  //运行程序前先注册OCX文件
  sfile:=ExtractFilePath(Application.ExeName)+myocx.ocx';
  if not FileExists(sfile) then
  begin
      ShowMessage(myocx.ocx文件丢失,请重新安装程序!');
      Application.Terminate;
  end;
 
  try
  OCXHand:=LoadLibrary(PChar(sfile));
  RegFunc:=GetProcAddress(OCXHand, 'DllRegisterServer');
  if RegFunc <> 0 then
  begin
    ShowMessage('myocx.ocx注册失败!');
    Application.Terminate;
  end;
  finally
    FreeLibrary(OCXHand);
  end;


  Application.CreateForm(TFrm_Main, Frm_Main);
  Application.Run;
end.

[/php]

  1. 01SaMDeditor V2.4 更新内容2026-12-02
  2. 02恭喜《轻武爱学习》小程序备案成功!2026-11-24
  3. 03SaView 图阅 1.1.1 更新日志2026-11-18
  4. 04Book2EPUB 1.0.4 更新日志2026-11-18
  5. 05SaView 图阅 一款轻便纯粹的看图工具2026-11-16
  6. 06免费工具Book2EPUB:轻松将电子书转换为 EPUB2026-11-11
  7. 07SaBlog2026 主题功能介绍(v1.1.36)2026-10-26
  8. 08PHP2Shell 重大安全漏洞事件深度分析报告2026-10-23
  9. 09LiteLLM v1.106.0 更新内容总结2026-10-20
  10. 10AI Native 受控软件工程2026-10-12
COMMENTS / 一纸留言

读者留言 0 条

一纸留言,便是山水间的一次相逢。

还没有留言,欢迎写下第一段交流。

WRITE A COMMENT

写下你的留言