在程序中注册OCX(50分)

C

chenby

Unregistered / Unconfirmed
GUEST, unregistred user!
本人在上几期中找到了有关注册ocx的解答,但是试了发现:
Uses Olectl,没有找到此单位。
而本人又不知道怎么找到TDllRegisterServer这个类的单元。
想请教各位高手。赶快来助我!
可以用代码在程序中实现ocx的注册. 举例如下:
(假设需要注册的文件为test.ocx)
uses OLEctl,....
var
OCXHand: THandle;
RegFunc: TDllRegisterServer;
begin
OCXHand:= LoadLibrary('c:/windows/system/test.ocx');
RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer')

if RegFunc <> 0 then ShowMessage('Error!');
FreeLibrary(OCXHand);
end;

 
olectl.pas在/source/rtl/win下.
 
不用olectl.pas,
只要把RegFunc声明为 function : HResult
stdcall;
。。。
type
TRegProc = function : HResult
stdcall;
。。。。
RegFunc:TRegProc ;
 
用最简单、最苯的方法:
WinExec("regsvr32.exe yourocx.ocx");
regsvr32.exe 这个文件很多地方都有,比如Visual Studio的光盘里或者Windows
的System目录里。把他和你的OCX文件放在一起。
 
不好意思,上面那行代码写错了,应该是:
WinExec("regsvr32.exe/s yourocx.ocx",SW_NORMAL);
 
多人接受答案了。
 

Similar threads

回复
0
查看
653
不得闲
S
回复
0
查看
739
SUNSTONE的Delphi笔记
S
S
回复
0
查看
619
SUNSTONE的Delphi笔记
S
顶部