Hi,
the only solution that I found is this: but this requires changes of the Hydra source code:
unit uHYCLRHelpers I changed the function IsVCLCompatible:
function IsVCLCompatible(const FileName: string): boolean;
var
Handle: THandle;
MydxInitialize: procedure; stdcall; //<--added
MydxFinalize: procedure; stdcall; //<--added
begin
Result := false;
Handle := LoadLibrary(PChar(FileName));
try
if Handle = INVALID_HANDLE_VALUE then exit;
@MydxInitialize := GetProcAddress(Handle, PChar('dxInitialize')); //<--added
if Assigned(MydxInitialize) then //<--added
MydxInitialize(); //<--added
result := Assigned(GetProcAddress(Handle,name_HYGetModuleController));
finally
@MydxFinalize := GetProcAddress(Handle, PChar('dxFinalize')); //<--added
if Assigned(MydxFinalize) then //<--added
MydxFinalize(); //<--added
FreeLibrary(Handle);
end;
end;
And the unit uHYVCLModule this methods:
constructor THYVCLModule.Create(aFileName: string);
var getmodulecontrollerfunc: TGetModuleControllerFunc;
initproc: TInitializeFinalizeHydraModule;
lLastError: Integer;
MydxInitialize: procedure; stdcall; //<--added
begin
fHandle := LoadLibrary(PChar(aFileName));
if (fHandle = 0) then begin
lLastError := GetLastError;
raise EHYException.CreateFmt(err_CannotLoadModule, [aFileName, lLastError, SysErrorMessage(lLastError)])
end;
@MydxInitialize := GetProcAddress(Handle, PChar('dxInitialize')); //<--added
if Assigned(MydxInitialize) then //<--added
MydxInitialize(); //<--added
inherited Create(aFileName);
@getmodulecontrollerfunc := GetProcAddress(fHandle, PChar(name_HYGetModuleController));
if (@getmodulecontrollerfunc=NIL)
then raise EHYException.CreateFmt(err_NotAnHydraModule, [aFileName])
else fModuleController := getmodulecontrollerfunc;
@initproc := GetProcAddress(fHandle, PChar(name_HYInitializeModule));
if (@initproc<>NIL) then initproc;
end;
destructor THYVCLModule.Destroy;
var
finproc: TInitializeFinalizeHydraModule;
Host : IHYHostAware;
MydxFinalize: procedure; stdcall; //<--added
begin
if (fHandle>0) then try
if Supports(fModuleController, IHYHostAware, Host) then begin
Host.Host := nil;
Host := nil;
end;
@finproc := GetProcAddress(fHandle, PChar(name_HYFinalizeModule));
if (@finproc<>NIL) then finproc;
@MydxFinalize := GetProcAddress(Handle, PChar('dxFinalize')); //<--added
if Assigned(MydxFinalize) then //<--added
MydxFinalize(); //<--added
finally
FreeLibrary(fHandle);
end;
inherited;
end;
In the dpr of the plugin I export the dxInitialize and dxFinalize methods:
library VisualModule;
uses
SysUtils,
Classes,
dxCore, //<--added
mcModuleController in 'mcModuleController.pas' {VisualModuleController: THYModuleController},
fVisualPlugin in 'fVisualPlugin.pas' {VisualPlugin: THYVisualPlugin};
{#HYDRAMODULE}
{$R *.res}
exports //<--added
dxInitialize, //<--added
dxFinalize; //<--added
begin
end.
Conceptually it is necessary to call dxInitialize as soon as the dll is loaded, and dxFinalize just before releasing it.
Whit this changes plugins with DevExpress components work fine.
Is it possible to find a solution so that Hydra already comes out with these changes? Or an alternative that does not require the modification of Hydra considering that calling dxInitialize and dxFinalize in the initialization and finalization of a unit does not work (or at least I could not get it to work)
Best Regards