我有這個代碼在Windows上註冊一個OCX。可以使用相同的代碼來註冊一個ActiveX DLL嗎?從Delphi應用程序註冊Activex DLL
請注意,程序在嵌入適當的清單後運行。
program RegOCX;
{$APPTYPE CONSOLE}
{$R *.res}
{$R RegOCX.rec}
uses
System.SysUtils, Vcl.OleCtnrs, OleCtl, Windows;
function CheckOCXReg: Boolean;
var
X: TOleContainer;
begin
Result := True;
X := TOleContainer.Create(nil);
try
try
X.Parent := nil;
X.CreateObject('KSDHTMLEDLib.KSEditX', False);
except
Result := False;
end;
finally
X.Free;
end;
end;
procedure RegisterOCX;
var
OCXFl: String;
OCXHandle: THandle;
RegFunc: TDllRegisterServer;
begin
OCXFl := ExtractFilePath(ParamStr(0)) + 'KsDHTMLEDLib.ocx';
if not FileExists(OCXFl) then
begin
WriteLn('Fatal Error - OCX file does not exist! Press Enter to continue..');
Readln;
Exit;
end;
OCXHandle := LoadLibrary(PChar(OCXFl));
try
if OCXHandle = 0 then
begin
WriteLn('Error registering OCX! Press Enter to continue..');
Readln;
end
else
begin
RegFunc := GetProcAddress(OCXHandle, 'DllRegisterServer');
if RegFunc <> 0 then
begin
WriteLn('Error registering OCX! Press Enter to continue..');
Readln;
end;
end;
finally
FreeLibrary(OCXHandle);
end;
end;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
RegisterOCX;
except
on E: Exception do
begin
WriteLn(E.ClassName, ': ', E.Message);
Readln;
end;
end;
end.
有包括德爾福TRegSvr樣本,看一看。 –