注册一个ocx的exe程序怎么写?

vitamines 2005-02-27 10:55:10
现有一个写完编译好的a.ocx,想写一个exe程序把a.ocx拷贝到c:\windows\systems32下,并注册(regsvr32 a.ocx),请问怎么做?
...全文
85 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunnysheng 2005-03-07
  • 打赏
  • 举报
回复
unsigned(僵哥) :你真厉害。
vitamines 2005-02-28
  • 打赏
  • 举报
回复
僵哥就是厉害,揭帖!
僵哥 2005-02-27
  • 打赏
  • 举报
回复
//反注册

hdll:=LoadLibrary('a.ocx');

DLLRegister(GetProcAddress(hdll,'DllUnregisterServer'))
僵哥 2005-02-27
  • 打赏
  • 举报
回复
type
DLLRegister=function :HResult;stdcall;//声明DLL(OCX)注册/反注册函数类型

procedure TForm1.Button1Click(Sender: TObject);
var
hdll:THandle; //Handle for LoadLibrary
FilePath:String; //Exists FilePath
sysdir:array[0..MAX_PATH] of char;//System Directory
len:UINT; //GetSystemDirectory
//返回值
begin
//获取当前应用程序路径
FilePath:=ExtractFilePath(Application.ExeName);

//路径最后非以'\'结束则加上'\'
if FilePath[Length(FilePath)]<>'\' then FilePath:=FilePath+'\';

//缓冲区清零
ZeroMemory(@sysdir,MAX_PATH+1);

//获取系统目录
//Win9x:Window\System
//WinNT:WINNT\System32
//WinXP/Win2003:Windows\System32
len:=GetSystemDirectory(sysdir,MAX_PATH+1);

//非以'\'置之以'\'结束
if sysdir[len-1]<>'\' then sysdir[len]:='\';

//复制文件
//将a.ocx从当前路径复制到系统目录
if CopyFile( PChar(FilePath+'a.ocx'), PChar(sysdir+'a.ocx'),False{覆盖同名文件}) then
begin
//与DLL同样进行装载并调用注册函数
hdll:=LoadLibrary(PChar(sysdir+'a.ocx'));
//注册
if DLLRegister(GetProcAddress(hdll,'DllRegisterServer'))=S_OK then
ShowMessage('注册成功')
else
ShowMessage('注册失败'+IntToStr(GetLastError));
end
else
ShowMessage('复制失败:'+IntToStr(GetLastError));

end;

5,391

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧