当前位置:主页>仓库管理软件> 列表

求动态将DLL加入系统目录System32下并注册(不知当 找服装店销售软件

仓库管理软件版1楼: 如题

2楼: “并注册”是说 regsvr32 XXX.dll 吗?
那样的话,直接写个资源文件包含XXX.dll,运行时释放到system32目录,接着winexec了事。

代码过于简单:
1.加个rc文件到工程里(省得自己用命令行编译),里面写上 MyDLL DAT XXX.dll
2.调用下面这个函数,调用是 ExtractRes(''DAT'',''MyDLL'',''XXX.dll'');

//释放文件到system32
procedure ExtractRes(ResType, ResName, ResNewName:String);
var Res:TResourceStream;
SystemDir:array[0..255] of char;
begin
GetSystemDirectory(SystemDir,sizeof(SystemDir))
Res:=TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
try
Res.SavetoFile(string(SystemDir)+''\''+ResNewName);
finally
Res.Free;
end;
end;

3.注册那个DLL吧,regsvr32不用理会操作系统 如服装店销售软件

3楼: 1)将文件复制到系统目录。
2)普通dll,就可以了,
如果是ocx.
直接运行ocx里面DllRegisterServer的函数和regsvr32 XXX.dll是完全一样.

4楼: 怎样将rc文件加到工程里

5楼: function RegisterOleFile (strOleFileName : STRING; OleAction : Byte ) : BOOLEAN;
const
RegisterOle = 1;//注册
UnRegisterOle = 0;//卸载
type
TOleRegisterFunction = function : HResult;//注册或卸载函数的原型
var
hLibraryHandle : THandle;//由LoadLibrary返回的DLL或OCX句柄
hFunctionAddress: TFarProc;//DLL或OCX中的函数句柄,由GetProcAddress返回
RegFunction : TOleRegisterFunction;//注册或卸载函数指针
begin
Result := FALSE;
//打开OLE/DCOM文件,返回的DLL或OCX句柄
hLibraryHandle := LoadLibrary(PCHAR(strOleFileName));
if (hLibraryHandle > 0) then//DLL或OCX句柄正确
try
//返回注册或卸载函数的指针
if (OleAction = RegisterOle) then//返回注册函数的指针
hFunctionAddress := GetProcAddress(hLibraryHandle, pchar(''DllRegisterServer''))
else//返回卸载函数的指针
hFunctionAddress := GetProcAddress(hLibraryHandle, pchar(''DllUnregisterServer''));

if (hFunctionAddress <> NIL) then//注册或卸载函数存在
begin
RegFunction := TOleRegisterFunction(hFunctionAddress);//获取操作函数的指针
if RegFunction >= 0 then //执行注册或卸载操作,返回值>=0表示执行成功
result := true;
end;
finally
FreeLibrary(hLibraryHandle);//关闭已打开的OLE/DCOM文件
end;

end;

function SystemDir: string;
var
dir: array [0..MAX_PATH] of Char;
begin
GetSystemDirectory(dir, MAX_PATH);
Result := StrPas(dir);
end;

procedure TForm1.InstallClick(Sender: TObject);
begin
CopyFile(PChar(ExtractFilePath(ParamStr(0))+''IEHelper.dll''),PChar(SystemDir+''\IEHelper.dll''),False);
if RegisterOleFile(SystemDir+''\IEHelper.dll'',1) then
msshow(''安装(Install)成功'')
end;

procedure TForm1.UnInstallClick(Sender: TObject);
begin
if RegisterOleFile(SystemDir+''\IEHelper.dll'',0) then
msshow(''卸载(UnInstall)成功'');

DeleteFile(SystemDir+''\IEHelper.dll'');

end;

6楼: 多人接受答案了。