سوال:ساخت كومپوننتي براي رجيستر كردن؟
سلام
مي خواستم بپرسم آيا ميشه Shamsi.dll رو بصورت يه كومپوننت رجيستر كرد .
مثلا با قرار دادن كومپوننت رو فرم و اكتيو كردنش خودش اون دي ال ال رو در سيستم مقصد رجيستر كنه ؟
كدهاي لازم براي رجيستر كردن هم اينان :
[PHP]
uses
Windows, SysUtils;
type
TDllRegisterServer = function: HResult; stdcall;
const
LIB_REGISTER = 'DllRegisterServer';
function IsHandle(Handle: THandle): Boolean;
function RegisterLibrary(szLibrary: String): Integer;
implementation
function IsHandle(Handle: THandle): Boolean;
begin
result:=(Handle <> 0); // Determine if a valid handle
end;
function RegisterLibrary(szLibrary: String): Integer;
var
hLib: THandle;
drs: TDllRegisterServer;
begin
hLib:=LoadLibrary(PChar(szLibrary)); // Attempt to load the library
if IsHandle(hLib) then
begin
// Get the register function
@drs:=GetProcAddress(hLib, LIB_REGISTER);
if Assigned(@drs) then
result:=drs// Make the function call
else
result:=GetLastError; // Return last error
// Unload the library
FreeLibrary(hLib);
end
else
// Return last error
result:=GetLastError;
end;
//*********************************************
procedure TFormmain.FormCreate(Sender: TObject);
var
windir:string;
begin
windir:=formmain.GetWinDir;
if not (fileexists(windir+'\system32\shamsi.dll')) then
begin
copyfile(pchar('require\shamsi.dll'),pchar(WinDir+ '\system32\shamsi.dll'),false);
formmain.RegisterLibrary(windir+'\system32\shamsi. dll');
end;
end;
[/PHP]