Results 1 to 2 of 2

Thread: problem when using qt dll in c#

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem when using qt dll in c#

    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.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem when using qt dll in c#

    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
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

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
  •  
Qt is a trademark of The Qt Company.