You're using the function wrong.
- You're using the hWnd variable on the same line as you declare it.
- And hWnd doesn't yet hold a reference to a viable window.
- And I have no idea why you're trying to put the int returned into an HWND variable. This makes no sense, and is the source of your errors.
- Again for the function to work, your HWND variable, hWnd needs to refer to a viable window handle. You may need to call another JNA function to get this handle.
e.g.,
User32 user32 = User32.INSTANCE;
char path[] = new char[512];
long sleepTime = 2000;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
HWND hWnd = user32.GetForegroundWindow();
user32.GetWindowModuleFileName(hWnd, path, 512);
System.out.println("Foreground Window Module FileName: " +
Native.toString(path));
user32.GetWindowText(hWnd, path, 512);
System.out.println("Window text is: " + Native.toString(path));