Troubles loading dll
-
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] -
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!
-
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.