delphistompclient icon indicating copy to clipboard operation
delphistompclient copied to clipboard

TMVCController in DLL

Open pieskov opened this issue 6 years ago • 0 comments

Hi.

How to use the TMVCController class in DLL?

In DLL `... TAdminCntrl = class(TMVCController)

end;

function getController(const AMVC: TMVCEngine): TMVCControllerClass; stdcall;

exports getController;

implementation

uses SysUtils, MVCFramework.Session, System.JSON;

function getController(const AMVC: TMVCEngine): TMVCControllerClass; stdcall; begin MVC := AMVC; Result := TAdminCntrl; end; ...`

In AppServer ... APath := GetDirectoryName(APath); Res := System.SysUtils.FindFirst(APath + '*.dll', faAnyFile, SR); try while Res = 0 do begin dll := LoadLibrary(PWideChar(APath + SR.Name)); if dll <> 0 then begin get_func := GetProcAddress(dll, 'getController'); FMVC.AddController(get_func(FMVC)); end; Res := FindNext(SR); end; finally System.SysUtils.FindClose(SR); end; ...

When you call this controller's method, the error "Invalid class typecast".

Thanks.

pieskov avatar Jul 24 '17 15:07 pieskov