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. Why WINAPI works differently in Qt
Forum Updated to NodeBB v4.3 + New Features

Why WINAPI works differently in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 4 Posters 6.2k 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.
  • jsulmJ jsulm

    @Engelard said in Why WINAPI works differently in Qt:

    it did'nt workout for some reason

    I explained you what you need to do.

    "How can i find out place where compiler of my VS2017 stored?" - that's why I suggested to look at "Compilers" tab in QtCreator - it will show you where the compiler is. Wasn't that the question you asked?

    EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #9

    @jsulm said in Why WINAPI works differently in Qt:

    I suggested to look at "Compilers" tab in QtCreator - it will show you where the compiler is. Wasn't that the question you asked?

    In that tab like 30 compilers. I asked for location of used compiler by VS, why would Qt know what my VS using?

    P.S. here is screen of my Kits where everything:

    alt text

    jsulmJ 1 Reply Last reply
    0
    • EngelardE Engelard

      @jsulm said in Why WINAPI works differently in Qt:

      I suggested to look at "Compilers" tab in QtCreator - it will show you where the compiler is. Wasn't that the question you asked?

      In that tab like 30 compilers. I asked for location of used compiler by VS, why would Qt know what my VS using?

      P.S. here is screen of my Kits where everything:

      alt text

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #10

      @Engelard Then please formulate more clear questions.
      "How can i find out place where compiler of my VS2017 stored?" - this asks for the location of your VS compiler, not for the compiler currently used in VS...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      EngelardE 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Engelard Then please formulate more clear questions.
        "How can i find out place where compiler of my VS2017 stored?" - this asks for the location of your VS compiler, not for the compiler currently used in VS...

        EngelardE Offline
        EngelardE Offline
        Engelard
        wrote on last edited by
        #11

        @jsulm "And i just can't find info in VS what compiler i use"

        Anyway where can i look in Visual Studio for info about compiler currently this IDE using?

        JonBJ 1 Reply Last reply
        0
        • EngelardE Engelard

          @jsulm "And i just can't find info in VS what compiler i use"

          Anyway where can i look in Visual Studio for info about compiler currently this IDE using?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #12

          @Engelard
          As well as sorting out what compilers you are using with @jsulm (which you definitely need to do):

          In the two sets of code, print/debug out at least the following values as you use them:

          sizeof(HMODULE)
          sizeof(modArr)
          cbNeeded
          sizeof(tempSTR)
          sizeof(infoVar)
          

          Any differences?

          Also: to a C++ expert:
          He uses

          char tempSTR[32];
          GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR))
          

          Is the use of char with GetModuleBaseNameA OK? Does it depend on UNICODE or sizeof(char) or something? Should the char be anything like w_char or TCHAR or similar, or the GetModuleBaseNameA() be GetModuleBaseNameW() or plain GetModuleBaseName()? Not my area....

          jsulmJ EngelardE 2 Replies Last reply
          0
          • JonBJ JonB

            @Engelard
            As well as sorting out what compilers you are using with @jsulm (which you definitely need to do):

            In the two sets of code, print/debug out at least the following values as you use them:

            sizeof(HMODULE)
            sizeof(modArr)
            cbNeeded
            sizeof(tempSTR)
            sizeof(infoVar)
            

            Any differences?

            Also: to a C++ expert:
            He uses

            char tempSTR[32];
            GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR))
            

            Is the use of char with GetModuleBaseNameA OK? Does it depend on UNICODE or sizeof(char) or something? Should the char be anything like w_char or TCHAR or similar, or the GetModuleBaseNameA() be GetModuleBaseNameW() or plain GetModuleBaseName()? Not my area....

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #13

            @JonB It is LPSTR according to https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getmodulebasenamea which in turn is char* according to https://msdn.microsoft.com/en-us/library/cc230353.aspx

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            JonBJ 1 Reply Last reply
            0
            • JonBJ JonB

              @Engelard
              As well as sorting out what compilers you are using with @jsulm (which you definitely need to do):

              In the two sets of code, print/debug out at least the following values as you use them:

              sizeof(HMODULE)
              sizeof(modArr)
              cbNeeded
              sizeof(tempSTR)
              sizeof(infoVar)
              

              Any differences?

              Also: to a C++ expert:
              He uses

              char tempSTR[32];
              GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR))
              

              Is the use of char with GetModuleBaseNameA OK? Does it depend on UNICODE or sizeof(char) or something? Should the char be anything like w_char or TCHAR or similar, or the GetModuleBaseNameA() be GetModuleBaseNameW() or plain GetModuleBaseName()? Not my area....

              EngelardE Offline
              EngelardE Offline
              Engelard
              wrote on last edited by
              #14

              @JonB No, all that stuff with char's does'nt matter because 'tital' number is wrong, and displaying of all that stuff after with simple char array works well.

              JonBJ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @JonB It is LPSTR according to https://docs.microsoft.com/en-us/windows/desktop/api/psapi/nf-psapi-getmodulebasenamea which in turn is char* according to https://msdn.microsoft.com/en-us/library/cc230353.aspx

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #15

                @jsulm
                This isn't my area, so you C++-ers must sort it out! But that doc link says stuff like:

                nSize
                The size of the lpBaseName buffer, in characters.

                That's characters, not bytes. And sizeof() returns, bytes, right? And he might be compiling UNICODE, right? Can I leave this all to you guys, if you're happy that's fine, it was just an observation....

                1 Reply Last reply
                0
                • EngelardE Engelard

                  @JonB No, all that stuff with char's does'nt matter because 'tital' number is wrong, and displaying of all that stuff after with simple char array works well.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #16

                  @Engelard

                  because 'tital' number is wrong

                  As I said above, I think you should print out the relevant sizeof()s used to calculate that....

                  EngelardE 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Engelard

                    because 'tital' number is wrong

                    As I said above, I think you should print out the relevant sizeof()s used to calculate that....

                    EngelardE Offline
                    EngelardE Offline
                    Engelard
                    wrote on last edited by
                    #17

                    @JonB Well, i found different cbNeeded (which inititally DWORD 0). Vs print that is 28(for my test app), when qt print 40.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #18

                      @Engelard said in Why WINAPI works differently in Qt:

                      Vs print that is 28(for my test app), when qt print 40.

                      That's what one would expect since when you link against Qt your app needs more modules.

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

                      JonBJ 1 Reply Last reply
                      2
                      • EngelardE Offline
                        EngelardE Offline
                        Engelard
                        wrote on last edited by
                        #19

                        Damn i found it!

                        There is one more function in WinApi with postfix Ex: EnumProcessModulesEx. As it said in documentation of first function(which in my example):

                        To control whether a 64-bit application enumerates 32-bit modules, 64-bit modules, or both types of modules, use the EnumProcessModulesEx function.

                        All was needed is add Ex to that function and one more parameter at the end LIST_MODULES_ALL

                        JonBJ 1 Reply Last reply
                        1
                        • Christian EhrlicherC Christian Ehrlicher

                          @Engelard said in Why WINAPI works differently in Qt:

                          Vs print that is 28(for my test app), when qt print 40.

                          That's what one would expect since when you link against Qt your app needs more modules.

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by
                          #20

                          @Christian-Ehrlicher
                          From OP's

                          how to print all modules of the selected program
                          void MWindow::printModules(DWORD id)

                          I assumed he was passing the id of another program's modules, not the one he is running! Just shows...

                          EngelardE 1 Reply Last reply
                          0
                          • EngelardE Engelard

                            Damn i found it!

                            There is one more function in WinApi with postfix Ex: EnumProcessModulesEx. As it said in documentation of first function(which in my example):

                            To control whether a 64-bit application enumerates 32-bit modules, 64-bit modules, or both types of modules, use the EnumProcessModulesEx function.

                            All was needed is add Ex to that function and one more parameter at the end LIST_MODULES_ALL

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #21

                            @Engelard
                            I did think it would be some 64-/32-bit issue...!!!
                            Yes, these days you must always look to see if a Windows function has a ...Ex() variant, there are so many of them now!

                            1 Reply Last reply
                            0
                            • JonBJ JonB

                              @Christian-Ehrlicher
                              From OP's

                              how to print all modules of the selected program
                              void MWindow::printModules(DWORD id)

                              I assumed he was passing the id of another program's modules, not the one he is running! Just shows...

                              EngelardE Offline
                              EngelardE Offline
                              Engelard
                              wrote on last edited by Engelard
                              #22

                              @JonB said in Why WINAPI works differently in Qt:

                              I assumed he was passing the id of another program's modules, not the one he is running! Just shows...

                              What :DD

                              ProcessID was100% correct.

                              JonBJ 1 Reply Last reply
                              0
                              • EngelardE Engelard

                                @JonB said in Why WINAPI works differently in Qt:

                                I assumed he was passing the id of another program's modules, not the one he is running! Just shows...

                                What :DD

                                ProcessID was100% correct.

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on last edited by JonB
                                #23

                                @Engelard

                                What :DD

                                ?

                                If you are saying you always pass the current process as id I would have expected you to use GetCurrentProcessId(). And in that case anyway, https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocess

                                If you are using GetCurrentProcessId as an argument to this function, consider using GetCurrentProcess instead of OpenProcess, for improved performance.

                                So you might know you're opening the current process, but I don't see anything in your post which indicated that, I assumed it was the id of another process you wanted to examine. Just saying....

                                EngelardE 1 Reply Last reply
                                0
                                • JonBJ JonB

                                  @Engelard

                                  What :DD

                                  ?

                                  If you are saying you always pass the current process as id I would have expected you to use GetCurrentProcessId(). And in that case anyway, https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocess

                                  If you are using GetCurrentProcessId as an argument to this function, consider using GetCurrentProcess instead of OpenProcess, for improved performance.

                                  So you might know you're opening the current process, but I don't see anything in your post which indicated that, I assumed it was the id of another process you wanted to examine. Just saying....

                                  EngelardE Offline
                                  EngelardE Offline
                                  Engelard
                                  wrote on last edited by
                                  #24

                                  @JonB said in Why WINAPI works differently in Qt:

                                  ?

                                  Sorry. From my view it seemed like you said that my input of ID was incorrect so function gives "wrong" result.

                                  JonBJ 1 Reply Last reply
                                  0
                                  • EngelardE Engelard

                                    @JonB said in Why WINAPI works differently in Qt:

                                    ?

                                    Sorry. From my view it seemed like you said that my input of ID was incorrect so function gives "wrong" result.

                                    JonBJ Online
                                    JonBJ Online
                                    JonB
                                    wrote on last edited by
                                    #25

                                    @Engelard OIC! NP :)

                                    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