Why WINAPI works differently in Qt
-
@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... -
@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?
@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 useschar tempSTR[32]; GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR))
Is the use of
char
withGetModuleBaseNameA
OK? Does it depend onUNICODE
orsizeof(char)
or something? Should thechar
be anything likew_char
orTCHAR
or similar, or theGetModuleBaseNameA()
beGetModuleBaseNameW()
or plainGetModuleBaseName()
? Not my area.... -
@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 useschar tempSTR[32]; GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR))
Is the use of
char
withGetModuleBaseNameA
OK? Does it depend onUNICODE
orsizeof(char)
or something? Should thechar
be anything likew_char
orTCHAR
or similar, or theGetModuleBaseNameA()
beGetModuleBaseNameW()
or plainGetModuleBaseName()
? Not my area....@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
-
@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 useschar tempSTR[32]; GetModuleBaseNameA(someHandle, modArr[i], tempSTR, sizeof(tempSTR))
Is the use of
char
withGetModuleBaseNameA
OK? Does it depend onUNICODE
orsizeof(char)
or something? Should thechar
be anything likew_char
orTCHAR
or similar, or theGetModuleBaseNameA()
beGetModuleBaseNameW()
or plainGetModuleBaseName()
? Not my area.... -
@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
@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 compilingUNICODE
, right? Can I leave this all to you guys, if you're happy that's fine, it was just an observation.... -
@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.
-
because 'tital' number is wrong
As I said above, I think you should print out the relevant
sizeof()
s used to calculate that.... -
@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.
-
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
-
@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.
@Christian-Ehrlicher
From OP'show 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... -
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
-
@Christian-Ehrlicher
From OP'show 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... -
@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.
What :DD
?
If you are saying you always pass the current process as
id
I would have expected you to useGetCurrentProcessId()
. And in that case anyway, https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocessIf 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....
-
What :DD
?
If you are saying you always pass the current process as
id
I would have expected you to useGetCurrentProcessId()
. And in that case anyway, https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocessIf 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....
-
@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.