Results 1 to 7 of 7

Thread: Delphi dll function import under QT

  1. #1
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Delphi dll function import under QT

    Hi!

    I heave a delphi dll, this exported function:

    Qt Code:
    1. function GetAdminSID: String;
    To copy to clipboard, switch view to plain text mode 

    How to import this function in QT?

    I use QLibrary to import but when I call the function GetAdminSID(); my application stopped with this message: "exited with code -1073741819"

    Qt Code:
    1. extern "C" { typedef char*(__stdcall * PGetAdminSID)(); }
    2. PGetAdminSID GetAdminSID;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. lib.setFileName("delphidll");
    2.  
    3. if (!lib.load())
    4. {
    5. qDebug("mainwindow: Can not load library!");
    6. return false;
    7. }
    8.  
    9. GetAdminSID = (PGetAdminSID)lib.resolve("GetAdminSID");
    10.  
    11. if (!GetMachineID)
    12. {
    13. lib.unload();
    14. qDebug("mainwindow: 'GetAdminSID' not found in library!");
    15. return false;
    16. }
    17.  
    18. return true;
    To copy to clipboard, switch view to plain text mode 

    Thanks!
    Hi!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Delphi dll function import under QT

    The third code section you posted: does it return true or false?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Delphi dll function import under QT

    Return true but when i call the imported function (GetAdminSID) the application terminated this message: "exited with code -1073741819"

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Delphi dll function import under QT

    Search our forums and/or msdn for C0000005. If I were to guess, I'd say you were passing an invalid parameter to the function or expecting an invalid return type. Or possibly the function requires some environment that is missing outside a Delphi program.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Gep (19th April 2011)

  6. #5
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Delphi dll function import under QT

    Function parameter is the problem:

    Qt Code:
    1. function GetAdminSID: String;
    To copy to clipboard, switch view to plain text mode 

    becouse I changed:

    Qt Code:
    1. function GetAdminSID: PChar;
    To copy to clipboard, switch view to plain text mode 

    Everything works fine.

    but unfortunately, this DLL is already in use. So I would not change. This version should I use:

    Qt Code:
    1. function GetAdminSID: String;
    To copy to clipboard, switch view to plain text mode 

    Is idea someones of the declaration I how to change?

    Qt Code:
    1. extern "C" { typedef char*(__stdcall * PGetAdminSID)(); }
    To copy to clipboard, switch view to plain text mode 

    Thanks!
    Hi!

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Delphi dll function import under QT

    You need to check what is the C representation for Delphi's String class. You can always work around the problem by using another dll that will contain a delphi function returning a PChar that will call your original function to serve as an adapter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    Gep (19th April 2011)

  9. #7
    Join Date
    Apr 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Delphi dll function import under QT

    Yes, if other is not so feasible. Although not very elegant solution. Still I look around

    Thanks for everything!
    Hi!

Similar Threads

  1. Convert Delphi Forms into QT4 ui's
    By jhering in forum Qt Tools
    Replies: 0
    Last Post: 12th September 2010, 09:43
  2. Replies: 4
    Last Post: 14th October 2009, 04:28
  3. Qt vs Delphi TApplicationEvents
    By BingoMaster in forum Newbie
    Replies: 1
    Last Post: 26th September 2009, 23:03
  4. Delphi and Qt4
    By dellegi in forum Qt Programming
    Replies: 0
    Last Post: 22nd April 2009, 16:28
  5. Qt us Builder and Delphi
    By zlatko in forum General Discussion
    Replies: 3
    Last Post: 8th May 2006, 09:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.