Friday, August 21, 2020

DLL and ActiveX Controls From a Delphi Application

DLL and ActiveX Controls From a Delphi Application A well known component of Delphiâ is the undertaking sending of an application with an executable document (exe).â However, on the off chance that the DLL or ActiveX controls in your venture are not enrolled on the users’ machines, a â€Å"EOleSysError† will be shown in light of running the exe file. To maintain a strategic distance from this, utilization the regsvr32.exe order line instrument. RegSvr32.exe Command Physically utilizing regsvr32.exe (Windows.Start - Run) will enroll and unregister self-registerable  DLL and ActiveX controls on a framework. Regsvr32.exe teaches the framework to endeavor to stack the segment and call its DLLSelfRegister work. In the event that this endeavor is fruitful, Regsvr32.exe shows a discourse demonstrating achievement. RegSvr32.exe has the accompanying order line options:â Regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname /s - Silent; show no message boxes /u - Unregister server /I - Call DllInstall passing it a discretionary [cmdline]; at the point when utilized with/u calls dll uninstall /n - don't call DllRegisterServer; this choice mustâ â â â â â be utilized with/iâ Call RegSvr32.exe Within Delphi code To call the regsvr32 instrument inside Delphi code, utilize the â€Å"RegisterOCX† capacity to execute a document and trust that the execution will wrap up. This is the means by which the RegisterOCX strategy could look: strategy RegisterOCX; type TRegFunc work : HResult; stdcall; var ARegFunc : TRegFunc; aHandle : THandle; ocxPath : string; start attempt ocxPath : ExtractFilePath(Application.ExeName) Flash.ocx; aHandle : LoadLibrary(PChar(ocxPath)); in the event that aHandle 0, at that point start ARegFunc : GetProcAddress(aHandle,DllRegisterServer); in the event that Assigned(ARegFunc) at that point start ExecAndWait(regsvr32,/s ocxPath); end; FreeLibrary(aHandle); end; but ShowMessage(Format(Unable to enroll %s, [ocxPath])); end; end; Note: the ocxPath variable focuses to the Flash.ocx Macromedia OCX. To have the option to enroll itself, an OCX must execute the DllRegisterServer capacity to make vault sections for all the classes inside the control. Try not to stress over the DllRegisterServer work, simply ensure it is there. For straightforwardness, it is assumed that the OCX is situated in a similar organizer as where the application may be. The ExecAndWait line in the above code calls the regsvr32 instrument by passing the/s switch alongside the full way to the OCX. The capacity is ExecAndWait. utilizes shellapi; ... work ExecAndWait(const ExecuteFile, ParamString : string): boolean; var SEInfo: TShellExecuteInfo; ExitCode: DWORD; start FillChar(SEInfo, SizeOf(SEInfo), 0); SEInfo.cbSize : SizeOf(TShellExecuteInfo); with SEInfo do start fMask : SEE_MASK_NOCLOSEPROCESS; Wnd : Application.Handle; lpFile : PChar(ExecuteFile); lpParameters : PChar(ParamString); nShow : SW_HIDE; end; in the event that ShellExecuteEx(SEInfo) at that point start rehash Application.ProcessMessages; GetExitCodeProcess(SEInfo.hProcess, ExitCode); until (ExitCode STILL_ACTIVE) or Application.Terminated; Result:True; end else Result:False; end; The ExecAndWait work utilizes the ShellExecuteEx API call to execute a record on a framework. For additional instances of executing any record from Delphi, look at how to execute and run applications and documents from Delphi code. Flash.ocx Inside Delphi Exe On the off chance that there is a need to enroll an ActiveX control on ​the user’s machine, at that point ensure the client has the OCX the program requires by setting the whole ActiveX (or DLL) inside the application’s exe as an asset. At the point when the OCX is put away inside the exe, it is anything but difficult to extricate, spare to plate, and call the RegisterOCX methodology.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.