PDA

View Full Version : problem when using qt dll in c#



duraganyolcu
19th December 2012, 13:49
Hi, i m trying to use qt code in c# project as a dll. i m using qt 4.8.1 in windows, with mingw. and qt creator ide. also i m using opencv 2.3.1 and boost 1.48 libraries. the project is running well as application, but when i use it as dll, it gives me runtime exception.

in my .cpp file, i m spesifying the function that i want to call from C# like this:


extern "C" __declspec(dllexport)bool myFunction();

to create dll and using qt codes as dll, i m editing .pro file like this:


TEMPLATE = lib

There is no problem while creating "myapp.dll". after dll is generated, i use this dll in c#, like this:


[DllImport("myapp.dll", EntryPoint = "myFunction")]
[return: System.Runtime.InteropServices.MarshalAsAttribute( System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool myFunction();

There is no linker error or something, function in dll does good job until this line;



cv::resize(frame, resized, resized.size(), 0, 0); //throws AccessViolationException.

if i set the "TEMPLATE = app", whole code works perfectly as an application, but if i edit like "TEMPLATE = lib", only opencv resize() function gives me runtime "AccessViolationException".

before this line, some opencv functions are used, but none of them throw any exception, for example,


cv::Mat frame = cv::imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE); //works well

. is there any idea about what i m missing?

my .pro files containing opencv libraries are given below.


INCLUDEPATH += C:\\OpenCV-2.3.1\\install\\include
LIBS += -LC:\\OpenCV-2.3.1\\install\\lib \
-lopencv_core231.dll \
-lopencv_highgui231.dll \
-lopencv_imgproc231.dll \
-lopencv_features2d231.dll \
-lopencv_calib3d231.dll \
-lopencv_video231.dll \
-lopencv_objdetect231.dll

sorry for long post.

amleto
19th December 2012, 21:56
cv::resize(frame, resized, resized.size(), 0, 0); //throws AccessViolationException.

AccessViolationException is a .net error, but that code line is c++, correct? So that doesn't make sense.

Sounds like you have a p/invoke problem. Nothing to do with Qt.

Please check your calling conventions. cdecl is default in c++, stdcall is default in c#. Please make sure the opencv dlls are on a path or locatable from the mayapp.dll