您现在的位置:首页 >> API >> API >> 内容

Delphi中注册汇编程序集RegisterAssembly

时间:2011/9/3 15:44:04 点击:

  核心提示:function RegisterAssembly(FileName: string): Boolean;type TRegAction = (raReg, raUnreg);type TAssemb...

function RegisterAssembly(FileName: string): Boolean;
type
  TRegAction = (raReg, raUnreg);
type
  TAssemblyRegProc = function(FileName: PChar;Reserved: Pointer) : Boolean stdcall;
const
  STRegAsm = 'tregasm.dll';
  SLoadFail = '加载文件%s失败';
  SRegFail = '在"%s"中调用%s失败';
  SCantFindProc = '在"%s"中无法找到 %s 过程';
  AssemblyProcName: array[TRegAction] of PChar = ('RegisterAssembly', 'UnregisterAssembly');
var
  RegProc: TAssemblyRegProc;
  SavedCW: Word;
  LibHandle: THandle;
  RegAction: TRegAction;
begin
  Result := False;
  RegAction:=raReg;
  SavedCW := Get8087CW;
  try
    Set8087CW($027f);
    LibHandle := LoadLibrary(PChar(STRegAsm));

    if LibHandle = 0 then raise Exception.CreateFmt(SLoadFail, [STRegAsm]);
    try
        @RegProc := GetProcAddress(LibHandle, PAnsiChar(AnsiString(AssemblyProcName[RegAction])));
      if @RegProc = nil then
        raise Exception.CreateFmt(SCantFindProc, [AssemblyProcName[RegAction],
          STRegAsm]);
      if not RegProc(PChar(FileName), nil) then
        raise Exception.CreateFmt(SRegFail, [AssemblyProcName[RegAction], STRegAsm]);
      Result := True;
    finally
      FreeLibrary(LibHandle);
    end;
  finally
    Set8087CW(SavedCW);
  end;
end;

作者:得闲 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2022 版权所有 All Rights Reserved.
  • 沪ICP备05001939号