Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I couldn't think a good title for this.Simple question

I couldn't think a good title for this.Simple question

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++learning
13 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Emrah Duatepe
    wrote on last edited by
    #1

    Hello friends,
    I am not able to understand this,could you help me.I am using Qt creature

    //This is in .h
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    void S7API CliCompletion(void *usrPtr, int opCode, int opResult);
    ~MainWindow();
    .
    .
    .

    //When I say right click and "add definition in mainwindow" I have got this in .cpp

    void MainWindow::CliCompletion(void *usrPtr, int opCode, int opResult)
    {

    }
    // Now, My problem what is S7API here,I have not encountered like this in C language.What does it do here.what is it.Where do I have to look in Dietel book.

    J L 2 Replies Last reply
    0
    • E Emrah Duatepe

      Hello friends,
      I am not able to understand this,could you help me.I am using Qt creature

      //This is in .h
      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      explicit MainWindow(QWidget *parent = 0);
      void S7API CliCompletion(void *usrPtr, int opCode, int opResult);
      ~MainWindow();
      .
      .
      .

      //When I say right click and "add definition in mainwindow" I have got this in .cpp

      void MainWindow::CliCompletion(void *usrPtr, int opCode, int opResult)
      {

      }
      // Now, My problem what is S7API here,I have not encountered like this in C language.What does it do here.what is it.Where do I have to look in Dietel book.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Such is often used to define a build specific calling convention (Calling convention - Wikipedia[^]). In your case it seems to be defined in snap7.h[^]:

      #ifdef OS_WINDOWS

      define S7API __stdcall

      #else

      define S7API

      #endif

      I don't know how it got there. It is not Qt related and the QtCreator is probably ignoring it. It looks like you have copied the function definition from somewhere into your header file.

      E 1 Reply Last reply
      0
      • E Emrah Duatepe

        Hello friends,
        I am not able to understand this,could you help me.I am using Qt creature

        //This is in .h
        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit MainWindow(QWidget *parent = 0);
        void S7API CliCompletion(void *usrPtr, int opCode, int opResult);
        ~MainWindow();
        .
        .
        .

        //When I say right click and "add definition in mainwindow" I have got this in .cpp

        void MainWindow::CliCompletion(void *usrPtr, int opCode, int opResult)
        {

        }
        // Now, My problem what is S7API here,I have not encountered like this in C language.What does it do here.what is it.Where do I have to look in Dietel book.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        This is not a C language issue, it is something to do with Qt. S7API is a define variable that will be in one of the Qt header files, and perhaps also in the documentation.

        E 1 Reply Last reply
        0
        • J Jochen Arndt

          Such is often used to define a build specific calling convention (Calling convention - Wikipedia[^]). In your case it seems to be defined in snap7.h[^]:

          #ifdef OS_WINDOWS

          define S7API __stdcall

          #else

          define S7API

          #endif

          I don't know how it got there. It is not Qt related and the QtCreator is probably ignoring it. It looks like you have copied the function definition from somewhere into your header file.

          E Offline
          E Offline
          Emrah Duatepe
          wrote on last edited by
          #4

          I added .h .c and .lib in my project so,so that it is defined in qt

          J 1 Reply Last reply
          0
          • L Lost User

            This is not a C language issue, it is something to do with Qt. S7API is a define variable that will be in one of the Qt header files, and perhaps also in the documentation.

            E Offline
            E Offline
            Emrah Duatepe
            wrote on last edited by
            #5

            This is in snap7 files

            1 Reply Last reply
            0
            • E Emrah Duatepe

              I added .h .c and .lib in my project so,so that it is defined in qt

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              Then there is no need to re-define and re-implement the function when already located in a library or an additional source file which has been added to the project. However, I think pointing to calling conventions should have answered your question.

              E 1 Reply Last reply
              0
              • J Jochen Arndt

                Then there is no need to re-define and re-implement the function when already located in a library or an additional source file which has been added to the project. However, I think pointing to calling conventions should have answered your question.

                E Offline
                E Offline
                Emrah Duatepe
                wrote on last edited by
                #7

                The function that I indicate above is related the example that it is client .I did just copy past properly.I wrote about calling convention and it say me ,you have to use macro with in .h and .c (prototype and function).Now, Qt didnt add the macro with function .I suppose I have to add .Am I right

                J 1 Reply Last reply
                0
                • E Emrah Duatepe

                  The function that I indicate above is related the example that it is client .I did just copy past properly.I wrote about calling convention and it say me ,you have to use macro with in .h and .c (prototype and function).Now, Qt didnt add the macro with function .I suppose I have to add .Am I right

                  J Offline
                  J Offline
                  Jochen Arndt
                  wrote on last edited by
                  #8

                  Don't add the macro to a Qt class function. You have two choices:

                  1. Use the existing header and source files from the examples and add them to your project. Then call the function using the name and include the header file in the source files where you call it.
                  2. Convert the examples by implementing all the code in Qt classes (source and header).

                  I would go for the first option. Than there is no need to implement a similar function as Qt class member. You might do so, but then the Qt function must not use the macro:

                  // MainWindow.h
                  class MainWindow : public QMainWindow
                  {
                  Q_OBJECT
                  public:
                  explicit MainWindow(QWidget *parent = 0);
                  ~MainWindow();
                  // No calling convention here because this is a Qt based C++ class member
                  void CliCompletion(void *usrPtr, int opCode, int opResult);
                  // ...
                  };

                  //MainWindow.cpp
                  #include "snap7.h"
                  #include "MainWindow.h"
                  // Other includes

                  void MainWindow::CliCompletion(void *usrPtr, int opCode, int opResult)
                  {
                  // Call the global implementation from other source file or library
                  ::CliCompletion(usrPtr, opCode, opResult);
                  }

                  E 2 Replies Last reply
                  0
                  • J Jochen Arndt

                    Don't add the macro to a Qt class function. You have two choices:

                    1. Use the existing header and source files from the examples and add them to your project. Then call the function using the name and include the header file in the source files where you call it.
                    2. Convert the examples by implementing all the code in Qt classes (source and header).

                    I would go for the first option. Than there is no need to implement a similar function as Qt class member. You might do so, but then the Qt function must not use the macro:

                    // MainWindow.h
                    class MainWindow : public QMainWindow
                    {
                    Q_OBJECT
                    public:
                    explicit MainWindow(QWidget *parent = 0);
                    ~MainWindow();
                    // No calling convention here because this is a Qt based C++ class member
                    void CliCompletion(void *usrPtr, int opCode, int opResult);
                    // ...
                    };

                    //MainWindow.cpp
                    #include "snap7.h"
                    #include "MainWindow.h"
                    // Other includes

                    void MainWindow::CliCompletion(void *usrPtr, int opCode, int opResult)
                    {
                    // Call the global implementation from other source file or library
                    ::CliCompletion(usrPtr, opCode, opResult);
                    }

                    E Offline
                    E Offline
                    Emrah Duatepe
                    wrote on last edited by
                    #9

                    So,You mean ,I must not use the macro because of the reason that you say.I added in my project .lib,.h,.c and Qt is handling this instead of me.I understand like this,I am new communication engineer this is why I dont know perfect C++. By the way I create a new function Clicompletion is the function that I create,I will use it any where. Maybe I got it wrong you.

                    J 1 Reply Last reply
                    0
                    • J Jochen Arndt

                      Don't add the macro to a Qt class function. You have two choices:

                      1. Use the existing header and source files from the examples and add them to your project. Then call the function using the name and include the header file in the source files where you call it.
                      2. Convert the examples by implementing all the code in Qt classes (source and header).

                      I would go for the first option. Than there is no need to implement a similar function as Qt class member. You might do so, but then the Qt function must not use the macro:

                      // MainWindow.h
                      class MainWindow : public QMainWindow
                      {
                      Q_OBJECT
                      public:
                      explicit MainWindow(QWidget *parent = 0);
                      ~MainWindow();
                      // No calling convention here because this is a Qt based C++ class member
                      void CliCompletion(void *usrPtr, int opCode, int opResult);
                      // ...
                      };

                      //MainWindow.cpp
                      #include "snap7.h"
                      #include "MainWindow.h"
                      // Other includes

                      void MainWindow::CliCompletion(void *usrPtr, int opCode, int opResult)
                      {
                      // Call the global implementation from other source file or library
                      ::CliCompletion(usrPtr, opCode, opResult);
                      }

                      E Offline
                      E Offline
                      Emrah Duatepe
                      wrote on last edited by
                      #10

                      #ifdef OS_WINDOWS # define S7API __stdcall #else # define S7API #endif Because of I use windows C++,I dont have to this with my functions,right?

                      J 1 Reply Last reply
                      0
                      • E Emrah Duatepe

                        So,You mean ,I must not use the macro because of the reason that you say.I added in my project .lib,.h,.c and Qt is handling this instead of me.I understand like this,I am new communication engineer this is why I dont know perfect C++. By the way I create a new function Clicompletion is the function that I create,I will use it any where. Maybe I got it wrong you.

                        J Offline
                        J Offline
                        Jochen Arndt
                        wrote on last edited by
                        #11

                        You must not use the macro with Qt classes (and should not use it with C++ classes). If you have another source file (or library) where the function is implemented, there is no need to implement it again as MainWindow class member. It is even not necessary to use the macro when the function is part of a C++ source file in your project. It is only necessary when using a C library. Then the header file tells the compiler that the function in the library uses that calling convention and that it must create corresponding code when creating the assembly code for the function call. C and C++ might use different calling conventions (depends also on the used compiler). Therefore, a compiler must know the calling convention when a C function is called from C++ code.

                        1 Reply Last reply
                        0
                        • E Emrah Duatepe

                          #ifdef OS_WINDOWS # define S7API __stdcall #else # define S7API #endif Because of I use windows C++,I dont have to this with my functions,right?

                          J Offline
                          J Offline
                          Jochen Arndt
                          wrote on last edited by
                          #12

                          It depends. See also my above post. Such constructs are not necessary for C++. But they are required when calling C functions from C++ code depending on how the C code has been build. If the C code is part of your project and you set the project options to compile C code as C++ (that is: use the C++ compiler also for C code), there is no need for the macro. But if the C code has been compiled as C for Windows, it must be used.

                          E 1 Reply Last reply
                          0
                          • J Jochen Arndt

                            It depends. See also my above post. Such constructs are not necessary for C++. But they are required when calling C functions from C++ code depending on how the C code has been build. If the C code is part of your project and you set the project options to compile C code as C++ (that is: use the C++ compiler also for C code), there is no need for the macro. But if the C code has been compiled as C for Windows, it must be used.

                            E Offline
                            E Offline
                            Emrah Duatepe
                            wrote on last edited by
                            #13

                            As a result of these informations, as far as I understand,I can call the functions just with name that intellisense show me functions,so that no problem with snap7 and I can create functions as I always do.This would be strange with macro.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups