Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Troubles loading dll
Forum Updated to NodeBB v4.3 + New Features

Troubles loading dll

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ldynasa
    wrote on last edited by
    #1

    Here I've got a dll written in C downloaded from the internet. The library is successfully loaded in Qt, functions resolved. But calling these methods causes the app to crash with "Segmentation fault". Besides, I've built a C# project in VS08 and loaded the library. Everything works again.

    Here's the code:
    1.dll library:

    void fdlib_detectfaces(unsigned char *imagedata, int imagewidth, int imageheight, int threshold);

    2.Qt app:

    @
    ushort graydata[10*10];
    QLibrary mylib("\fdlib.dll");
    bool okLoad = mylib.load();
    bool loaded = mylib.isLoaded();
    typedef void (FdetectFace)(ushort,int,int,int);
    FdetectFace detectFace = (FdetectFace)mylib.resolve("fdlib_detectfaces");

    //app crashes here
    detectFace(&graydata[0],10,10,0);
    @

    3.C# implementation:

    @
    [DllImport("fdlib.dll")]
    unsafe public static extern void fdlib_detectfaces(ushort*data,int w,int h,int threshold);

    unsafe
    {
    UInt16[] image = new ushort[10 * 10];
    fixed (ushort* ptr = &image[0])
    {
    //app works fine here
    fdlib_detectfaces(ptr, 10, 10, 0);
    }
    }
    @

    [EDIT: fixed code formatting, pleas use @-tags, Volker]
    [EDIT: fixed title, Andre]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Why don't you link against the library, if you have the headers available? This way you can use the functions directly.

      Also, the signature of the function is

      @
      void fdlib_detectfaces(unsigned char *imagedata, int imagewidth, int imageheight, int threshold);
      @

      but you search for

      @
      (ushort*,int,int,int)
      @

      in resolve. I suspect resolve() to return a null pointer. You did not check the function pointer!

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ldynasa
        wrote on last edited by
        #3

        Thanx 4 the reply!
        I've checked the returned function pointer and it's not null.

        Could you talk more specifically about linking against the library?
        Does it means include the header in the project?:D

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Then you should run a debugger and look in the backtrace where the error occurs.

          And, yes, linking means including the header and link against the library.

          I suggest you make yourself comfortable with C/C++ basics first (includes, linking libs, etc.), before you dive into the real advanced topic of dynamically resolving library symbols.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vishwajeet
            wrote on last edited by
            #5

            Try this http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/proguide/ref/compile_library.htm

            Born To Code !!!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved