[delphi] OCX 등록 및 해제
// (COM Server) OCX 등록 및 해제
// usage:
// RegOCX('C:\Test.ocx');
unit ocxUtils;
interface
uses
Windows, SysUtils, ComObj;
procedure RegOCX(const DLLName: string);
procedure UnRegOCX(const DLLName: string);
implementation
procedure RegOCX(const DLLName: string);
begin
if FileExists(DLLName) then
RegisterComServer(DLLName);
end;
procedure UnRegOCX(const DLLName: string);
type
TRegProc = function: HResult; stdcall;
const
RegProcName = 'DllUnregisterServer';
var
Handle: THandle;
RegProc: TRegProc;
begin
Handle := SafeLoadLibrary(DLLName);
if Handle <= HINSTANCE_ERROR then
raise Exception.CreateFmt('%s: %s', [SysErrorMessage(GetLastError), DLLName]);
try
RegProc := GetProcAddress(Handle, RegProcName);
if Assigned(RegProc) then OleCheck(RegProc) else RaiseLastOSError;
finally
FreeLibrary(Handle);
end;
end;
end.
--------------------------------------------------------------
// DLL 레지스트리에 등록
// DllRegisterServer 함수 : Olectl.h
// DllUnregisterServer 함수 참조
--------------------------------------------------------------
// DLL 레지스트리에 등록
// DllRegisterServer 함수 : Olectl.h
// DllUnregisterServer 함수 참조
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var OCXHand: THandle; begin OCXHand:=LoadLibrary('c:\windows\system\test.ocx'); if (GetProcAddress(OCXHand, 'DllRegisterServer')<>nil) then ShowMessage('Error!'); FreeLibrary(OCXHand); end; end.
반응형
'Delphi, RadStudio' 카테고리의 다른 글
[delphi] Registering DLL and ActiveX controls from code (0) | 2011.11.28 |
---|---|
[delphi] COM Server or ActiveX OCX 등록 및 해제 (0) | 2011.11.28 |
[개발/delphi] TMemo 에서 라인 선택하기 (0) | 2011.10.29 |
[개발/delphi] 중복 실행 방지 (0) | 2011.09.01 |
[개발/delphi] 절대 죽지 않는 프로그램 만들기 (0) | 2011.08.01 |
댓글