Friday, August 21, 2020

DLL and ActiveX Controls From a Delphi Application

DLL and ActiveX Controls From a Delphi Application A mainstream highlight of Delphiâ is the task organization of an application with an executable document (exe).â However, on the off chance that the DLL or ActiveX controls in your venture are not enlisted on the users’ machines, a â€Å"EOleSysError† will be shown because of running the exe file. To stay away 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 trains the framework to endeavor to stack the part and call its DLLSelfRegister work. On the off chance that this endeavor is fruitful, Regsvr32.exe shows an exchange 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 alternative mustâ â â â â â be utilized with/iâ Call RegSvr32.exe Within Delphi code To call the regsvr32 device inside Delphi code, utilize the â€Å"RegisterOCX† capacity to execute a record and trust that the execution will wrap up. This is the manner by which the RegisterOCX technique could look: method 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)); on the off chance that aHandle 0, at that point start ARegFunc : GetProcAddress(aHandle,DllRegisterServer); on the off chance 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 actualize the DllRegisterServer capacity to make library sections for all the classes inside the control. Try not to stress over the DllRegisterServer work, simply ensure it is there. For effortlessness, it is assumed that the OCX is situated in a similar organizer as where the application seems to 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 document on a framework. For additional instances of executing any document from Delphi, look at how to execute and run applications and records 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 circle, and call the RegisterOCX strategy.

No comments:

Post a Comment

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