java


Getting hWnd from current process


I tried to get hWnd from current process using GetCurrentProcess function to display path to each process. But I got an error in this line: User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
How to convert it to the desired type?
The method GetWindowThreadProcessId(WinDef.HWND, IntByReference) in the type User32 is not applicable for the arguments (WinNT.HANDLE, IntByReference)
There is my code:
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
kernel32.GetCurrentProcess();
HANDLE hWnd = kernel32.GetCurrentProcess();
User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010,
false, pid.getValue());
psapi.GetModuleFileNameExA(process, null, path, 1024);
System.out.println(Native.toString(path));
}
} finally {
kernel32.CloseHandle(snapshot);
}
UPD:
The problem was solved in this way:
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010,
false, processEntry.th32ProcessID.intValue());
if (process != null) {
int len = psapi.GetModuleFileNameExW(process, null, path,
1024);
if (len > 0) {
System.out.println(new String(path, 0, len));
} else {
System.out.println("GetModuleFileNameW failed");
}
} else {
System.out.println(kernel32.GetLastError());
}
System.out.println(process != null ? Native.toString(path) : "error");
}
} finally {
kernel32.CloseHandle(snapshot);
}
Thank you for help!
A) get a list of Process Identifiers (PID) using the Win32 API EnumProcesses or the Win32 APIs CreateToolhelp32Snapshot / Process32First / Process32Next / CloseHandle
B) with each PID, use the win32 API OpenProcess to obtain a HANDLE for the process (request for PROCESS_QUERY_INFORMATION as dwDesiredAccess). With that handle, use the Win32 API GetProcessImageFileName (and do not forget to close the HANDLE with CloseHandle)
Hope this helps (as that's not JAVA code, sorry for that)

Related Links

Add sound effects at particular time in a Video file
Is Canvas onDraw timed?
Database unable to store in html format
JSON returning date in Epoch format in Spring Mvc Hibernate
Executing bash via Java process builder
How to do multiple Hibernate restrictions on a List
using LanguageTool whilst retaining HTML formatting (TinyMCE)
Is ZeroMQ server listening infinitely?
Realm Database omitting a string when saving
Implementing Alarms in java restful microservices similar like AlarmManager in Android
Running maven plugins on artifact's pom file
Log4j behaviour in read only filesystem
Custom Event Listener for Multi threaded environment in Java Using Wait() and notify()
Initializing chromium cause app ANR
Swift 3 equivalent for Java property with type that implements specific interface
Mocking an Apache Commons CSV CSVRecord

Categories

HOME
java
yii2
atom-editor
hook
urbancode
stock
react-router
paw-app
alpha
mvvmcross
constraint-programming
append
gitpitch
dacpac
gnupg
fancybox-3
user-input
vb.net-2010
quickfix
worldwind
after-effects
interop
google-pagespeed
jprofiler
jtextfield
clickonce
errorlevel
functional-testing
mustache.php
telerik-reporting
php-openssl
firebase-crash-reporting
centos6.5
fluentvalidation
assistant
facebook-apps
lightswitch-2013
uisplitview
uiswipegesturerecognizer
catalog
main
unobtrusive-validation
ws-security
particles.js
reportingservices-2005
eigenvalue
password-encryption
turbogears
.net-4.6.2
thin
babel-core
logfiles
user-accounts
azure-application-gateway
pebble-watch
dropbox-php
elgg
drupal-6
kbuild
account-kit
mediaelement
messenger
jquery-filter
grails-tomcat-plugin
radtreelist
trash
measures
xml-attribute
contact-list
ios4
wapiti
netmq
qtableview
qdialog
citrus-pay
sailfish-os
census
pretty-print
tt-news
markers
neolane
mesa
uitouch
ftps
back-stack
mylyn
lcs
flashvars
coderush
cinema-4d
sudzc
web-application-design
nsviewanimation
thunderbird-lightning
genealogy
post-build

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App