Results 1 to 4 of 4

Thread: QLibrary::resolve() crash on return

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QLibrary::resolve() crash on return

    I am able to invoke a procedure in my DLL successfully, and all seems OK until the execution is complete. On return from the DLL procedure my Qt application crashes silently.

    I am executing the DLL from within a thread.

    void ExecThread::run()
    {
    ...
    QLibrary myLib(dll_path);

    typedef int (*MyPrototype)(int *, char *, int, char *, int, char *, int, char *, int);
    MyPrototype execute = (MyPrototype) myLib.resolve("EXECUTE");
    if (execute) {
    execute(...)
    }
    myLib.unload();
    }

    If I comment out the call to execute() the program doesn't crash. I suspect the problem is stack related. My DLL is in Fortran90, and there is a trick to passing strings from C to Fortran. My Fortran subroutine expects an integer (by reference) and four strings, each of which is passed as a pair of arguments, a C string and an int holding the string length. This works fine in Python (using windll.LoadLibrary()), and almost works here, since the subroutine executes correctly.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary::resolve() crash on return

    Sounds like the C routine was expecting the called function to fix up the stack, but the function was expecting the caller to fix up the stack. So the called function works correctly, but then your program will crash shortly afterwards, as the stack offset will be incorrect.

    Have you tried changing the calling convention?

  3. #3
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QLibrary::resolve() crash on return

    I agree that it looks like an issue of who has responsibility for cleaning up the stack. I'm using STDCALL, which as I understand it is the correct calling convention for calling Fortran from C. To be precise this is what I'm using:

    subroutine execute(ncpu,infile,outfile,resfile,runfile)
    !DEC$ ATTRIBUTES DLLEXPORT :: EXECUTE
    !DEC$ ATTRIBUTES STDCALL, REFERENCE, MIXED_STR_LEN_ARG, ALIAS:"EXECUTE" :: execute
    integer :: ncpu
    character*(*) :: infile,outfile,resfile,runfile

    I confess to not really understanding all the ins and outs of calling conventions, and when in doubt I usually consult the experts at the Intel Fortran forum. I do need to provide them with the correct info, since they are not very familiar with C++, and less with Qt. Am I correct in thinking that I need the convention for calling from C?

  4. #4
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QLibrary::resolve() crash on return

    I've changed to:
    !DEC$ ATTRIBUTES C, REFERENCE, MIXED_STR_LEN_ARG, ALIAS:"EXECUTE" :: execute
    and now it works. This is a bit annoying since it means I need different DLLs for the C++ and the Python versions of my Qt application.
    Thanks.

Similar Threads

  1. QLibrary in PyQt
    By Urthas in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 18:46
  2. QLibrary resolve problem
    By Nippler in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 15:37
  3. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 14:03
  4. Can somebody resolve this issue???
    By im_rajya in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 10:37
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:23

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.