Problem testing with windows api
-
Hi guys
here a little code snippetQList<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 : 0xc0000005Now 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 -
Hi guys
here a little code snippetQList<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 : 0xc0000005Now 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@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)? -
@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)? -
@JonB Hi
of course I only copied revelant files, ill be looking in deployement to see if it helps me@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. -
@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.@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 -
@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. -
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?
-
yes I did redeploy when release
Found the problem
here is the new codeHANDLE 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 -
yes I did redeploy when release
Found the problem
here is the new codeHANDLE 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@JulsPower
That does look more reasonable, i wasn't sure what the MS docs were telling you to do. Which implies you were in theAnother 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 :)