I'm getting an access violation when I try to link to a function within a DLL file. DLL was made in Delphi 6 and we are upgrading to Delphi 11 (wild jump I know). So the code once upon a time worked and somewhere in the many changes to Delphi has come crumbling down. The Delphi environment is running on a Windows 10 machine. The DLL in use has been compiled and built within Delphi 11 (though components have changed). Delphi claims that it can compile and build, if that is where this issue possibly lies I can get more code as I have the source (and project files) for the DLL.
procedure TForm1.Button1Click(Sender: TObject);
type
TShowUserList = function : TForm; stdcall;
var
LHandle: THandle;
LUserList : TShowUserList;
LForm : TForm;
begin
LHandle := LoadLibrary('E:\D11 Projects\Test Dll\Win32\Debug\BOUsers.Dll');
if LHandle <> 0 then
begin
@LUserList := GetProcAddress(LHandle, 'ShowUserList');
if @LUserList <> nil then
begin
LForm := LUserList; //Here is where error shows, doesn't even get to the ShowUserList function
end;
end;
end;
When debugging, when I get to LForm := LUserList
, LUserList
is an 'inaccessible value'. Which would make sense as to why the error is occurring.
And within the BOUsers.dll is a UserList form,
FUNCTION ShowUserList : TForm;
BEGIN
IF NOT G.FormExists('UsersListForm') THEN
BEGIN
UsersListForm := TUsersListForm.Create(Application);
Result := UsersListForm;
END
ELSE
Result := G.ReturnForm('UsersListForm');
END;
EXPORTS
ShowUserList;
Debugging doesn't even enter here (I have made sure debugging is enabled for the dll, though it seemingly was by default). I'd be slightly happy if I could get into this code and debug!
I'm aware there isn't the full amount of error handling (not that there was much on the D6 version). However this is just a test project to help figure out the issue in the main application, I can add it if needs be though.
My expectation is that LForm
would be the UserListForm
within the dll and that I'd be able to display it within a window pane, debug it for issues and use it as expected.
I've tried to look through various similar questions on StackOverflow (though if I've missed one feel free to link it and I will look through it). Copied the example embarcadero supplied.
Honestly, haven't worked with DLL's before past applications were all units and forms within the exe basically.