Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 32-Bit Qt crashes when calling a 32-bit DLL function (char*)
Forum Updated to NodeBB v4.3 + New Features

32-Bit Qt crashes when calling a 32-bit DLL function (char*)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 364 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NoobyLost
    wrote on 19 May 2024, 16:03 last edited by NoobyLost
    #1

    My 32-bit Qt windows application crashes whenever it calls a specific function from a 32-bit DLL. Other functions from this DLL work fine... only the following causes an "Exception Triggered" by an "inferior":

    int16_t deviceInit (const char* filePath);
    And I'm calling it via:

    const char cstr[] = { "C:\\File.bin"};
    deviceInit (cstr);
    

    I'm thinking maybe it's how characters/strings/unicode are passed.. or some mismatch in the compiler settings/multithread, or MSVC versions.

    I'm using Qt 5.15.2 MSVC2019 32-bit (17.9.3462). I tried the C/C++ compiler options to "x86_amd64" as well "x86", but it still crashes. Also tried en/disabling "Force UTF-8 MSVC compiler output".

    As a test, I built a Win32 application using VS Studio 2022 and calling the DLL function works fine. If the path or file is bad, the function returns an error code, but it does not cause a crash. Since VS Studio and Qt are using the same compiler, maybe it's the build system / linker ? MSBuild , CMake ?

    The setup in VS Studio is a bit different than Qt.. I had to point the Library directory to the folder containing McxApi.lib and then use:

    #pragma comment(lib, "McxAPI") 
    

    VS Studio shows the compile and linker command-line settings to be

    /JMC /permissive- /ifcOutput "ConsoleA.3e145a6e\Debug\" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"ConsoleA.3e145a6e\Debug\vc143.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /FC /Fa"ConsoleA.3e145a6e\Debug\" /EHsc /nologo /Fo"ConsoleA.3e145a6e\Debug\" /Fp"ConsoleA.3e145a6e\Debug\ConsoleApplication1.pch" /diagnostics:column 
    
    /OUT:"C:\Projects\Temp\9\ConsoleApplication1\Debug\ConsoleApplication1.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Projects\Temp\9\ConsoleApplication1\Debug\ConsoleApplication1.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"C:\Projects\Temp\9\ConsoleApplication1\Debug\ConsoleApplication1.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"ConsoleA.3e145a6e\Debug\ConsoleApplication1.exe.intermediate.manifest" /LTCGOUT:"ConsoleA.3e145a6e\Debug\ConsoleApplication1.iobj" /ERRORREPORT:PROMPT /ILK:"ConsoleA.3e145a6e\Debug\ConsoleApplication1.ilk" /NOLOGO /TLBID:1 
    

    In Qt, the make and .pro settings are:

    C:/Qt/5.15.2/msvc2019/bin/qmake.exe C:\Projects\Temp\8\test\source\test.pro -spec win32-msvc "CONFIG+=debug" "CONFIG-=qml_debug" && C:/Users/temp/msvc_make.bat qmake_all
    
    QT += core gui  quick
    #INCLUDEPATH += $$PWD/
    LIBS += -L$$PWD/libfolder -lMcxAPI  
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    CONFIG += c++11
    ...
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 19 May 2024, 16:06 last edited by
      #2

      Don't see what Qt has to do with this crash. Normally when a program crashes you look into the backtracce to see what's going wrong. Since your string does only contain ASCII characters this is for sure no encoding problem.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hskoglund
        wrote on 19 May 2024, 17:29 last edited by
        #3

        Hi just a guess, but I notice for the VS Studio 2022 compilation you're using the /sdl switch which sets pointers in your classes to nullptr at start (as a debugging help) but I don't see that switch in your Qt .pro file for MSVC 2019.
        Maybe if you try removing the /sdl switch (or adding it to the .pro file) the builds will behave less differently.

        N 1 Reply Last reply 20 May 2024, 15:02
        0
        • H hskoglund
          19 May 2024, 17:29

          Hi just a guess, but I notice for the VS Studio 2022 compilation you're using the /sdl switch which sets pointers in your classes to nullptr at start (as a debugging help) but I don't see that switch in your Qt .pro file for MSVC 2019.
          Maybe if you try removing the /sdl switch (or adding it to the .pro file) the builds will behave less differently.

          N Offline
          N Offline
          NoobyLost
          wrote on 20 May 2024, 15:02 last edited by
          #4

          @hskoglund Thanks, was definitely worth a shot! I couldn't find how to enable SDL in Qt, but in VS Studio it's easy to disable (Project's Configuration Properties- > C/C++ -> General-> SDL Checks). Unfortunately, the function call works in VS with or without the SDL Checks, so sadly it doesn't seem like that's the difference.

          The same cl.exe compiler is used in VS and QT (C:\Program Files...\Hostx86\x86\MS "19.39.33521 for x86"), but I don't see which linker is used. Neither VS nor QT are using link.exe.

          Looking at the API, there is no other function that takes a char*, but there is another function that returns it
          GetErrorDescription(int16_t, char*);
          and this function does not cause a crash.. so it's only passing the char pointer into the dll function, and only in Qt, that causes a crash.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hskoglund
            wrote on 20 May 2024, 18:00 last edited by
            #5

            Ok, it was a nice try :-)
            So compiler is the same but what about the app itself, is it really the same for Qt and Visual Studio? To me it looks like Visual Studio builds a console app without any calls to Qt and the Qt build is for a gui/QML flavored app.
            I.e. to debug this I think you need to use the same app for both of the build environments.

            1 Reply Last reply
            0

            1/5

            19 May 2024, 16:03

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved