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:

Qt Code:
  1. extern "C" __declspec(dllexport)bool myFunction();
To copy to clipboard, switch view to plain text mode 

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

Qt Code:
  1. TEMPLATE = lib
To copy to clipboard, switch view to plain text mode 

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

Qt Code:
  1. [DllImport("myapp.dll", EntryPoint = "myFunction")]
  2. [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
  3. public static extern bool myFunction();
To copy to clipboard, switch view to plain text mode 

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


Qt Code:
  1. cv::resize(frame, resized, resized.size(), 0, 0); //throws AccessViolationException.
To copy to clipboard, switch view to plain text mode 

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,

Qt Code:
  1. cv::Mat frame = cv::imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE); //works well
To copy to clipboard, switch view to plain text mode 

. is there any idea about what i m missing?

my .pro files containing opencv libraries are given below.

Qt Code:
  1. INCLUDEPATH += C:\\OpenCV-2.3.1\\install\\include
  2. LIBS += -LC:\\OpenCV-2.3.1\\install\\lib \
  3. -lopencv_core231.dll \
  4. -lopencv_highgui231.dll \
  5. -lopencv_imgproc231.dll \
  6. -lopencv_features2d231.dll \
  7. -lopencv_calib3d231.dll \
  8. -lopencv_video231.dll \
  9. -lopencv_objdetect231.dll
To copy to clipboard, switch view to plain text mode 

sorry for long post.