usesWinProcs; ... begin WinExec(......); …. end. 和调用Pascal库函数没什么两样。
直接加载它并调用DLLREGISTER接口
uses OleCtl //..\Borland\Delphi6\Source\Rtl\Win\OleCtl.pas var OCXHand: THandle; RegFunc: TDllRegisterServer; begin Try OCXHand:= LoadLibrary('c:\test.ocx'); RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer'); if RegFunc <> 0 then MessageBox(Application.Handle,'不能注册文件!','信息提示', MB_ICONINFORMATION+MB_OK); else MessageBox(Application.Handle,'注册文件成功!','信息提示', MB_ICONINFORMATION+MB_OK); finally FreeLibrary(OCXHand); end; end;
uses OleCtl //文件在目录下:'..\Borland\Delphi6\Source\Rtl\Win\OleCtl.pas' var OCXHand: THandle; RegFunc: TDllRegisterServer; begin Try OCXHand:= LoadLibrary('c:\test.ocx'); RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer'); if RegFunc <> 0 then MessageBox(Application.Handle,'不能注册文件!','信息提示', MB_ICONINFORMATION+MB_OK) else MessageBox(Application.Handle,'注册文件成功!','信息提示', MB_ICONINFORMATION+MB_OK); finally FreeLibrary(OCXHand); end; end;
How to register an OCX Your installation program needs to register an OCX, but doesn't support this? Or you want to register it by your program yourself? Suppose the OCX you want to use is called program RegisterMyOCX; uses OLECtl, Windows, Dialogs; var OCXHand: THandle; RegFunc: TDllRegisterServer; //add to the uses clause begin OCXHand:= LoadLibrary('c:\windows\system\test.ocx'); RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer'); //case sensitive if RegFunc <> 0 then RegFunc else ShowMessage('Error!') FreeLibrary(OCXHand); // You can the same way unregister the OCX: // replace 'DllRegisterServer' by 'DllUnregisterServer' end.
...
begin
WinExec(......);
….
end.
和调用Pascal库函数没什么两样。
var
OCXHand: THandle;
RegFunc: TDllRegisterServer;
begin
Try
OCXHand:= LoadLibrary('c:\test.ocx');
RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer');
if RegFunc <> 0 then
MessageBox(Application.Handle,'不能注册文件!','信息提示',
MB_ICONINFORMATION+MB_OK);
else
MessageBox(Application.Handle,'注册文件成功!','信息提示',
MB_ICONINFORMATION+MB_OK);
finally
FreeLibrary(OCXHand);
end;
end;
var
OCXHand: THandle;
RegFunc: TDllRegisterServer;
begin
Try
OCXHand:= LoadLibrary('c:\test.ocx');
RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer');
if RegFunc <> 0 then
MessageBox(Application.Handle,'不能注册文件!','信息提示',
MB_ICONINFORMATION+MB_OK)
else
MessageBox(Application.Handle,'注册文件成功!','信息提示',
MB_ICONINFORMATION+MB_OK);
finally
FreeLibrary(OCXHand);
end;
end;
Your installation program needs to register an OCX, but doesn't support this? Or you want to
register it by your program yourself? Suppose the OCX you want to use is called
program RegisterMyOCX;
uses
OLECtl, Windows, Dialogs;
var
OCXHand: THandle;
RegFunc: TDllRegisterServer; //add to the uses clause
begin
OCXHand:= LoadLibrary('c:\windows\system\test.ocx');
RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer'); //case sensitive
if RegFunc <> 0 then
RegFunc
else
ShowMessage('Error!')
FreeLibrary(OCXHand); // You can the same way unregister the OCX:
// replace 'DllRegisterServer' by 'DllUnregisterServer'
end.
或
WinExec
不过还是用
ShellExceute
保险点
要把regsvr32.exe那个文件也打包到程序中才行。
不然有的机器没有regsvr32就死定了。还是同意楼上一星级战友的意见!