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. Generate a DLL with __stdcall calling convention
QtWS25 Last Chance

Generate a DLL with __stdcall calling convention

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 15.7k 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.
  • R Offline
    R Offline
    ramanujam
    wrote on 30 Mar 2012, 15:12 last edited by
    #1

    Hi,

    I am generating a shared library(DLL) in Windows using QT Creator. I am facing a problem with this shared library (DLL).

    I have to generate a Library with __stdcall calling convention. By default it is created with __cdecl calling convention.

    I want to override this calling convention.

    Could you please help me to achieve this.

    Thanks & Regards,
    Ramanujam

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 30 Mar 2012, 17:40 last edited by
      #2

      Hi Ramanujam,

      Qt does not do anything magic for this. If you want to export the funcation with __stdcall, you should add "__stdcall" to the function, which is exactly the same as you do when you using pure C/C++.

      Regards,

      Debao

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ramanujam
        wrote on 31 Mar 2012, 06:13 last edited by
        #3

        Hi Debao,

        Thanks for your answer. Actually I am aware of __stdcall.
        I will explain you the problem what I am facing.

        I am using third party library where all functions are in __stdcall calling convention. Third party library is a static library and it has a header file.

        Static library has a function
        void __stdcall SomeFunction()
        {
        }

        but in header file its prototype is
        void SomeFunction();

        What is happening is when I include header file in my Shared library(DLL) is
        SomeFunction() is considered as __cdecl because __stdcall is missing from prototype declaration in header file and Shared library by default was compiled in __stdcall calling convention.

        When I call SomeFunction() from my DLL it is giving a linker error because calling convention is mismatching with the function definition.

        I contacted the third party vendor and they said I have to change the project settings to __stdcall (/Gz) compiler option. It will solve the problem. For testing purpose I changed the prototype declaration to
        void __stdcall SomeFunction(); then Shared library is linking fine. But this is not the correct solution because third party library is licensed and I can't change the header file of a third party library.

        I hope you understood the problem. What I want is how can I change the QT project settings to include __stdcall convention similar to Visual studio where you change the calling convention from Project-->Properties-->C/C++-->Advanced-->Calling Convention.

        Basically what I need is How to include the library which uses __stdcall convention for all the functions with the DLL which uses __cdecl convention...............

        Please help me.....

        Thanks & Regards,
        Ramanujam

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on 31 Mar 2012, 22:51 last edited by
          #4

          You can add following line to your .pro file.
          @
          QMAKE_CFLAGS += /Gz
          QMAKE_CXXFLAGS += /Gz
          @

          Regards,

          Debao

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ramanujam
            wrote on 1 Apr 2012, 02:54 last edited by
            #5

            Thanks a lot....

            Linking with third party library is fine now. But due this compiler option there is one more linker error in QString.

            I have done one sample and below are the steps

            1. Created a shared library to include QtCore modules
            2. included QtCore in my cpp file and added
              QString test = QString::number(5000); to convert number into a QString.
            3. Then added the
              QMAKE_CFLAGS += /Gz
              QMAKE_CXXFLAGS += /Gz
              int the .pro file
            4. Rebuild entire project

            There are linker errors for these QString. If I remove above options from a .pro file it links successfully.
            My observation is accessing all static member functions of a class are giving linker error with this compiler option.
            For Example:
            quint64 g_ulCurrentPID = QCoreApplication::applicationPid();
            Also my project settings include "UNICODE" and "No (/Zc:wchar_t-)". I tried with "treat _wchar_t as default Built-in Type" as Yes. Still I am facing the same problem.

            Could you please help to solve this linker error

            Thanks & Regards,
            Ramanujam

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vsbrar
              wrote on 22 Oct 2012, 12:55 last edited by
              #6

              I'm facing a similar problem changing calling convention to cdecl gives "Interlocked" errors in files qatomic_windows.h and intrin.h. I'm tried on Visual Studio using QT VS Plugin and QT Creator.

              Steps to recreate:
              Visual Studio

              Create a QT console application.

              VS properties -> Configuration Properties -> C/C++ -> Advanced -> Calling Convention.

              Change to __stdcall (/Gz)

              Qt Creator

              Create a console or any other application

              In the .pro file add the following lines

              QMAKE_CFLAGS += /Gz
              QMAKE_CXXFLAGS += /Gz

              Build the project

              Platform Details:
              Windows 7 64 bit
              Visual Studio 2010
              QT Version 4.8.2

              1 Reply Last reply
              0

              • Login

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