注册及卸载dll或ocx文件过程

来源:互联网 发布:linux哪个方面 编辑:程序博客网 时间:2024/05/22 13:16

function RegisterOleFile (strOleFileName : STRING; OleAction : Byte ) : BOOLEAN;

const

    RegisterOle = 1;//注册

    UnRegisterOle = 0;//卸载

type

    TOleRegisterFunction = function : HResult;//注册或卸载函数的原型

var

    hLibraryHandle : THandle;//由LoadLibrary返回的DLL或OCX句柄

    hFunctionAddress: TFarProc;//DLL或OCX中的函数句柄,由GetProcAddress返回

    RegFunction : TOleRegisterFunction;//注册或卸载函数指针

begin

Result := FALSE;

//打开OLE/DCOM文件,返回的DLL或OCX句柄

hLibraryHandle := LoadLibrary(PCHAR(strOleFileName));

if (hLibraryHandle > 0) then//DLL或OCX句柄正确

   try

      //返回注册或卸载函数的指针

      if (OleAction = RegisterOle) then

          hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllRegisterServer')) //返回
注册函数的指针

      else  hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllUnregisterServer'));
//返回卸载函数的指针

      if (hFunctionAddress <> NIL) then//注册或卸载函数存在

          begin

          RegFunction := TOleRegisterFunction(hFunctionAddress);//获取操作函数的指针

          if RegFunction >= 0 then //执行注册或卸载操作,返回值>=0表示执行成功

              result := true;

          end;

   finally

      FreeLibrary(hLibraryHandle);//关闭已打开的OLE/DCOM文件

   end;

end;

 

原创粉丝点击