Results 1 to 4 of 4

Thread: dll loading trouble

  1. #1
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    1

    Default dll loading trouble

    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:

    Qt Code:
    1. ushort graydata[10*10];
    2. QLibrary mylib("\\fdlib.dll");
    3. bool okLoad = mylib.load();
    4. bool loaded = mylib.isLoaded();
    5. typedef void (*FdetectFace)(ushort*,int,int,int);
    6. FdetectFace detectFace = (FdetectFace)mylib.resolve("fdlib_detectfaces");
    7.  
    8. //app crashes here
    9. detectFace(&graydata[0],10,10,0);
    To copy to clipboard, switch view to plain text mode 
    3.C# implementation:

    [DllImport("fdlib.dll")]
    Qt Code:
    1. unsafe public static extern void fdlib_detectfaces(ushort*data,int w,int h,int threshold);
    2.  
    3. public static void TestFace()
    4. {
    5. unsafe
    6. {
    7. UInt16[] image = new ushort[10 * 10];
    8. fixed (ushort* ptr = &image[0])
    9. {
    10. fdlib_detectfaces(ptr, 10, 10, 0);
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 23rd February 2011 at 15:04.

  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: dll loading trouble

    see comments in code:

    Qt Code:
    1. ushort *graydata = NULL; //[10*10]; no need to initialize since detecFaces allocates the memory.
    2. QLibrary mylib("\\fdlib.dll");
    3. bool okLoad = mylib.load();
    4. //You should really check for errors!
    5. if(!okLoad){
    6. //handle error
    7. return;
    8. }
    9. bool loaded = mylib.isLoaded();
    10. if(!loaded){
    11. //TDOD: handle error
    12. return;
    13. }
    14. typedef void (*FdetectFace)(ushort*,int,int,int);
    15. FdetectFace detectFace = (FdetectFace)mylib.resolve("fdlib_detectfaces");
    16. if(detectFace ){
    17. //app crashes here
    18. detectFace(graydata,10,10,0);
    19. }
    20.  
    21. //at some point you should release the data allocted in detectFace:
    22. if(graydata)
    23. delete graydata;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. unsafe public static extern void fdlib_detectfaces(ushort*data,int w,int h,int threshold);
    2.  
    3. unsafe
    4. {
    5. UInt16[] image = new ushort[10 * 10];
    6. fixed (ushort* ptr = &image[0])
    7. {
    8. //app works fine here
    9. fdlib_detectfaces(ptr, 10, 10, 0); //this calls recursively - does nothing, and never ends!! which is probably why it crashes.
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    ==========================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. The following user says thank you to high_flyer for this useful post:

    ldynasa (23rd February 2011)

  4. #3
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    1

    Default Re: dll loading trouble

    Thanx for the reply!
    I've checked the loading status in the debug session so I've omitted the checking codes.

    Besides, I've updated the last part to avoid confusion

  5. #4
    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: dll loading trouble

    Again, your detectFace function does nothing except call its self endlessly - that is why it is crashing.
    ==========================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.

Similar Threads

  1. QGLWidget trouble again
    By John82 in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2009, 10:58
  2. QGLWidget trouble
    By John82 in forum Qt Programming
    Replies: 9
    Last Post: 31st July 2009, 01:03
  3. SQL trouble
    By xmeister in forum Newbie
    Replies: 2
    Last Post: 25th March 2009, 11:53
  4. trouble with Qt-4 with kubuntu 8.04
    By impeteperry in forum Installation and Deployment
    Replies: 2
    Last Post: 25th July 2008, 16:21
  5. New to QT..need help guys..sorry for the trouble
    By neomax in forum General Discussion
    Replies: 2
    Last Post: 17th November 2006, 16:20

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.