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. Problem testing with windows api
Forum Updated to NodeBB v4.3 + New Features

Problem testing with windows api

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 58 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.
  • J Offline
    J Offline
    JulsPower
    wrote last edited by
    #1

    Hi guys
    here a little code snippet

    QList<structSessionInfo> MainWindow::getSessionInfo()
    {
        HANDLE hServer = NULL;
        int i;
        structSessionInfo stSessionInfo;
        QList<structSessionInfo> qlSessionInfo;
    
        qlSessionInfo.clear();
        hServer = WTSOpenServerA("127.0.0.1");
        if(hServer)
        {
            DWORD pLevel = 1;
            PWTS_SESSION_INFO_1A *pSessionInfo;
            DWORD pCount;
            QMessageBox::information(this, "Nouvelle donnée", "before session");
            if(WTSEnumerateSessionsExA(hServer, &pLevel, 0, pSessionInfo, &pCount) != 0)
            {
                QMessageBox::information(this, "Nouvelle donnée", "session");
                for(i=0; i<pCount; i++)
                {
                    stSessionInfo.session = pSessionInfo[i]->pSessionName;
                    stSessionInfo.sUser= pSessionInfo[i]->pUserName;
                    stSessionInfo.State = pSessionInfo[i]->State;
                    qlSessionInfo.append(stSessionInfo);
                }
                WTSFreeMemoryExA(WTSTypeSessionInfoLevel1, pSessionInfo, pCount);
            }
            QMessageBox::information(this, "Nouvelle donnée", "Close");
            WTSCloseServer(hServer);
        }
        QMessageBox::information(this, "Nouvelle donnée", "return");
        return qlSessionInfo;
    }
    

    When in qt creator that work fine
    when im outside it does crash at line if(WTSEnumerateSessionsExA(hServer, &pLevel, 0, pSessionInfo, &pCount) != 0)
    no error application just close, I have an error logged in windows event:
    Nom de l’application défaillante : SessionChecker.exe, version : 0.0.0.0, horodatage : 0x686e4a4e
    Nom du module défaillant : WTSAPI32.dll, version : 10.0.26100.4484, horodatage : 0xebedc398
    Code d’exception : 0xc0000005

    Now I if I put the qt bin in my path and remove the dll from the dll it does work
    If I try the same trick on another machine it does crash at the same line.

    is there anything wrong? anyone have idea?
    I can put more code if you want
    Thanks

    JonBJ 1 Reply Last reply
    0
    • J JulsPower

      Hi guys
      here a little code snippet

      QList<structSessionInfo> MainWindow::getSessionInfo()
      {
          HANDLE hServer = NULL;
          int i;
          structSessionInfo stSessionInfo;
          QList<structSessionInfo> qlSessionInfo;
      
          qlSessionInfo.clear();
          hServer = WTSOpenServerA("127.0.0.1");
          if(hServer)
          {
              DWORD pLevel = 1;
              PWTS_SESSION_INFO_1A *pSessionInfo;
              DWORD pCount;
              QMessageBox::information(this, "Nouvelle donnée", "before session");
              if(WTSEnumerateSessionsExA(hServer, &pLevel, 0, pSessionInfo, &pCount) != 0)
              {
                  QMessageBox::information(this, "Nouvelle donnée", "session");
                  for(i=0; i<pCount; i++)
                  {
                      stSessionInfo.session = pSessionInfo[i]->pSessionName;
                      stSessionInfo.sUser= pSessionInfo[i]->pUserName;
                      stSessionInfo.State = pSessionInfo[i]->State;
                      qlSessionInfo.append(stSessionInfo);
                  }
                  WTSFreeMemoryExA(WTSTypeSessionInfoLevel1, pSessionInfo, pCount);
              }
              QMessageBox::information(this, "Nouvelle donnée", "Close");
              WTSCloseServer(hServer);
          }
          QMessageBox::information(this, "Nouvelle donnée", "return");
          return qlSessionInfo;
      }
      

      When in qt creator that work fine
      when im outside it does crash at line if(WTSEnumerateSessionsExA(hServer, &pLevel, 0, pSessionInfo, &pCount) != 0)
      no error application just close, I have an error logged in windows event:
      Nom de l’application défaillante : SessionChecker.exe, version : 0.0.0.0, horodatage : 0x686e4a4e
      Nom du module défaillant : WTSAPI32.dll, version : 10.0.26100.4484, horodatage : 0xebedc398
      Code d’exception : 0xc0000005

      Now I if I put the qt bin in my path and remove the dll from the dll it does work
      If I try the same trick on another machine it does crash at the same line.

      is there anything wrong? anyone have idea?
      I can put more code if you want
      Thanks

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by
      #2

      @JulsPower
      When you want to run a Qt application outside of Creator you have to deploy it first, which ensures correct libraries etc. are findable. What have you done about properly deploying your app on either your own machine or the other one (not just manually copying the odd file you think is relevant)?

      J 1 Reply Last reply
      3
      • JonBJ JonB

        @JulsPower
        When you want to run a Qt application outside of Creator you have to deploy it first, which ensures correct libraries etc. are findable. What have you done about properly deploying your app on either your own machine or the other one (not just manually copying the odd file you think is relevant)?

        J Offline
        J Offline
        JulsPower
        wrote last edited by
        #3

        @JonB Hi
        of course I only copied revelant files, ill be looking in deployement to see if it helps me

        JonBJ 1 Reply Last reply
        0
        • J JulsPower

          @JonB Hi
          of course I only copied revelant files, ill be looking in deployement to see if it helps me

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by JonB
          #4

          @JulsPower said in Problem testing with windows api:

          of course I only copied revelant files

          And how do you know what these are? How do you know you did not kiss(!) miss others which are needed? That is what proper "deployment" does for you. At a guess you might have either missing DLLs or wrong versions picked up from elsewhere on machines. Try using windeployqt and compare what libraries it packages for your application with what you believe is "relevant"?

          Another possibility is that the issue has nothing to do with Qt or deployment but rather is a "bug" which only happens to show up in certain environments or circumstances. Such as a memory access issue. I had a quick glance at your WTSEnumerateSessionsExA() and it seemed OK to me, but you might want to try it standalone without any Qt stuff to make sure that works across environments.

          J 2 Replies Last reply
          0
          • JonBJ JonB

            @JulsPower said in Problem testing with windows api:

            of course I only copied revelant files

            And how do you know what these are? How do you know you did not kiss(!) miss others which are needed? That is what proper "deployment" does for you. At a guess you might have either missing DLLs or wrong versions picked up from elsewhere on machines. Try using windeployqt and compare what libraries it packages for your application with what you believe is "relevant"?

            Another possibility is that the issue has nothing to do with Qt or deployment but rather is a "bug" which only happens to show up in certain environments or circumstances. Such as a memory access issue. I had a quick glance at your WTSEnumerateSessionsExA() and it seemed OK to me, but you might want to try it standalone without any Qt stuff to make sure that works across environments.

            J Offline
            J Offline
            JulsPower
            wrote last edited by
            #5

            @JonB Well sir you were right, before now I only copied the qt dll (needed when running the app), platform folder and plugin needed and worked quite enough :)

            but after using windeploy the application function great outside the developpement environement.
            thanks alog now ill be using this way in the future

            1 Reply Last reply
            1
            • JonBJ JonB

              @JulsPower said in Problem testing with windows api:

              of course I only copied revelant files

              And how do you know what these are? How do you know you did not kiss(!) miss others which are needed? That is what proper "deployment" does for you. At a guess you might have either missing DLLs or wrong versions picked up from elsewhere on machines. Try using windeployqt and compare what libraries it packages for your application with what you believe is "relevant"?

              Another possibility is that the issue has nothing to do with Qt or deployment but rather is a "bug" which only happens to show up in certain environments or circumstances. Such as a memory access issue. I had a quick glance at your WTSEnumerateSessionsExA() and it seemed OK to me, but you might want to try it standalone without any Qt stuff to make sure that works across environments.

              J Offline
              J Offline
              JulsPower
              wrote last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • J Offline
                J Offline
                JulsPower
                wrote last edited by
                #7

                there is still something going on, doesn't work on my remote machine and if I compile in release instead of debug doesn't work on my dev machine either. any idea?

                1 Reply Last reply
                0
                • JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote last edited by JonB
                  #8

                  I assume you re-run windeployqt and re-deploy fully when swapping from debug to release? windeployqt should give you a runnable application, if not you have some strange situation. And are deploying correct/consistent Qt versions & files. And is the error/crash still exactly as you showed it at start now? Also you did start out from a properly consistent, fetched and installed version of Qt on your machine?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JulsPower
                    wrote last edited by
                    #9

                    yes I did redeploy when release
                    Found the problem
                    here is the new code

                        HANDLE hServer = NULL;
                        int i;
                        structSessionInfo stSessionInfo;
                        QList<structSessionInfo> qlSessionInfo;
                    
                        qlSessionInfo.clear();
                        hServer = WTSOpenServerA("192.168.55.13");
                        if(hServer)
                        {
                            DWORD pLevel = 1;
                            PWTS_SESSION_INFO_1A pSessionInfo;
                            DWORD pCount;
                            //QMessageBox::information(this, "Info", "before session");
                            if(WTSEnumerateSessionsExA(hServer, &pLevel, 0, &pSessionInfo, &pCount) != 0)
                            {
                                //QMessageBox::information(this, "Info", "session");
                                for(i=0; i<pCount; i++)
                                {
                                    //QMessageBox::information(this, "Info", "1");
                                    stSessionInfo.session = pSessionInfo[i].pSessionName;
                                    stSessionInfo.sUser= pSessionInfo[i].pUserName;
                                    stSessionInfo.State = pSessionInfo[i].State;
                                    //QMessageBox::information(this, "Info", "4");
                                    qlSessionInfo.append(stSessionInfo);
                                    //QMessageBox::information(this, "Info", "5");
                                }
                                //QMessageBox::information(this, "Info", "before free");
                                WTSFreeMemoryExA(WTSTypeSessionInfoLevel1, pSessionInfo, pCount);
                            }
                            //QMessageBox::information(this, "Info", "Close");
                            WTSCloseServer(hServer);
                        }
                        //QMessageBox::information(this, "Info", "return");
                        return qlSessionInfo;
                    

                    PWTS_SESSION_INFO_1A pSessionInfo had to be define like this not as a pointer, first it was PWTS_SESSION_INFO_1A *pSessionInfo
                    then gave me consistent error when define as PWTS_SESSION_INFO_1A *pSessionInfo = NULL

                    JonBJ 1 Reply Last reply
                    1
                    • J JulsPower

                      yes I did redeploy when release
                      Found the problem
                      here is the new code

                          HANDLE hServer = NULL;
                          int i;
                          structSessionInfo stSessionInfo;
                          QList<structSessionInfo> qlSessionInfo;
                      
                          qlSessionInfo.clear();
                          hServer = WTSOpenServerA("192.168.55.13");
                          if(hServer)
                          {
                              DWORD pLevel = 1;
                              PWTS_SESSION_INFO_1A pSessionInfo;
                              DWORD pCount;
                              //QMessageBox::information(this, "Info", "before session");
                              if(WTSEnumerateSessionsExA(hServer, &pLevel, 0, &pSessionInfo, &pCount) != 0)
                              {
                                  //QMessageBox::information(this, "Info", "session");
                                  for(i=0; i<pCount; i++)
                                  {
                                      //QMessageBox::information(this, "Info", "1");
                                      stSessionInfo.session = pSessionInfo[i].pSessionName;
                                      stSessionInfo.sUser= pSessionInfo[i].pUserName;
                                      stSessionInfo.State = pSessionInfo[i].State;
                                      //QMessageBox::information(this, "Info", "4");
                                      qlSessionInfo.append(stSessionInfo);
                                      //QMessageBox::information(this, "Info", "5");
                                  }
                                  //QMessageBox::information(this, "Info", "before free");
                                  WTSFreeMemoryExA(WTSTypeSessionInfoLevel1, pSessionInfo, pCount);
                              }
                              //QMessageBox::information(this, "Info", "Close");
                              WTSCloseServer(hServer);
                          }
                          //QMessageBox::information(this, "Info", "return");
                          return qlSessionInfo;
                      

                      PWTS_SESSION_INFO_1A pSessionInfo had to be define like this not as a pointer, first it was PWTS_SESSION_INFO_1A *pSessionInfo
                      then gave me consistent error when define as PWTS_SESSION_INFO_1A *pSessionInfo = NULL

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by
                      #10

                      @JulsPower
                      That does look more reasonable, i wasn't sure what the MS docs were telling you to do. Which implies you were in the

                      Another possibility is that the issue has nothing to do with Qt or deployment but rather is a "bug" which only happens to show up in certain environments or circumstances. Such as a memory access issue. I had a quick glance at your WTSEnumerateSessionsExA() and it seemed OK to me, but you might want to try it standalone without any Qt stuff to make sure that works across environments.

                      situation! The Qt and deployment changes simply showed or masked the problem. But you have still learnt what you should do to e.g. deploy to another machine, or be sure it works on yours outside of the Creator development environment which should be useful :)

                      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