Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel32.INSTANCE.SetPriorityClass is missing! #1538

Closed
dEajL3kA opened this issue Aug 4, 2023 · 7 comments
Closed

Kernel32.INSTANCE.SetPriorityClass is missing! #1538

dEajL3kA opened this issue Aug 4, 2023 · 7 comments

Comments

@dEajL3kA
Copy link
Contributor

dEajL3kA commented Aug 4, 2023

Provide complete information about the problem

  1. Version of JNA and related jars: 5.13.0
  2. Version and vendor of the java virtual machine: OpenJDK 17.0.8 LTS
  3. Operating system: Windows
  4. System architecture (CPU type, bitness of the JVM): x86-64, 64-Bit
  5. Complete description of the problem: Kernel32.INSTANCE.SetPriorityClass is missing!
  6. Steps to reproduce: Try to call SetPriorityClass() from Kernel32.INSTANCE → it won't work !!! 😠

Details

According to the example code, this must work:

private static void parsePriority(String priority) {
    if (Platform.isWindows()) {
        /* .... */
        if (priorityClass != 0) {
            Kernel32.INSTANCE.SetPriorityClass(Kernel32.INSTANCE.GetCurrentProcess(), priorityClass); // <-- !!!
        }
    } else {
        System.err.println("Process priority setting is only available on Windows platform.");
    }
}

Reality: Required function is missing!
grafik

The function does exist in Kernel32.DLL, that's for sure:
https://learn.microsoft.com/de-de/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass

Where has Kernel32.INSTANCE.SetPriorityClass() gone in JNA ?!?!

@matthiasblaesing
Copy link
Member

@dEajL3kA
Copy link
Contributor Author

dEajL3kA commented Aug 4, 2023

The example code is not JNA, of course. It uses JNA !!!

It calls Kernel32.INSTANCE.SetPriorityClass(), which is imported from com.sun.jna.platform.win32.Kernel32.

SetPriorityClass() exists in Kernel32.DLL, so must be available in Kernel32.INSTANCE.

And yes, before you ask, I do have the required jna-platform-5.13.0 JAR file in my class path, downloaded straight from Maven.

@matthiasblaesing
Copy link
Member

No it does not. The project is just hijacking the JNA namespace. Check here:

https://github.com/jindrapetrik/jpexs-decompiler/blob/master/src/com/sun/jna/platform/win32/Kernel32.java#L215

the project uses its own set of mappings and not the JNA ones.

@dEajL3kA
Copy link
Contributor Author

dEajL3kA commented Aug 4, 2023

The function SetPriorityClass() does exist in Kernel32.DLL, that's for sure:
https://learn.microsoft.com/de-de/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass

SetPriorityClass function

Minimum supported client: Windows XP
Minimum supported server: Windows Server 2003
Header: processthreadsapi.h
Library: Kernel32.lib
DLL: Kernel32.dll

Then why the function can not be found in Kernel32.INSTANCE from com.sun.jna.platform.win32.Kernel32? 😕

(And yes, before you ask, I do have the required jna-platform-5.13.0 JAR file in my class path)

If the function can not be found, and if I'm not missing anything obvious, this means JNA's Kernel32.INSTANCE is incomplete!

@matthiasblaesing
Copy link
Member

I never doubted, that the function exists in the DLL, you are asserting though, that the function is bound, this is not the case. JNA provides only part of the glue for calling into native. It still needs to to get the information required to call the function and there the bindings come in. People bind what they need and contribute this work here so that others can benefit from that, as they benefited from aleady bound functions.
In contrast to java the native code does not hold enough information to reflectively call into functions. C uses header files to provide that information, but these headers are only available at compile time, not at runtime.

@dblock
Copy link
Member

dblock commented Aug 10, 2023

This is a feature request to add SetPriorityClass to JNA. @dEajL3kA please contribute!

@dEajL3kA
Copy link
Contributor Author

dEajL3kA commented Aug 11, 2023

This is a feature request to add SetPriorityClass to JNA. @dEajL3kA please contribute!

Since this issue was closed immediately, I had to create a new one that adds the required methods.

Also, initially, it wasn't clear to me that these functions have never existed in "official" JNA, as some examples found on the Internet (not official JNA examples, but examples that use JNA) indicate that they already exist, or have existed at some point 😏

Please see here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants