Skip to content

Commit

Permalink
Fix java doc, change parameter types and update CHANGES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
overpathz committed Mar 29, 2023
1 parent 2e96df4 commit e935d9c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -7,6 +7,7 @@ Next Release (5.14.0)

Features
--------
* [#1514](https://github.com/java-native-access/jna/pull/1514): Add `SetThreadUILanguage`, `SetThreadPreferredUILanguages` and `GetThreadUILanguage` in `c.s.j.p.win32.Kernel32` - [@overpathz](https://github.com/overpathz).

Bug Fixes
---------
Expand Down
20 changes: 10 additions & 10 deletions contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java
Expand Up @@ -26,7 +26,6 @@
import com.sun.jna.LastErrorException;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.StringArray;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
Expand Down Expand Up @@ -4399,13 +4398,7 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
* to use on the Windows console.
* </p>
*
* @param LangId Language identifier for the user interface language for the thread.
*
* @return Returns the input language identifier if successful.
* If the input identifier is nonzero, the function returns that value.
* If the language identifier is 0, the function always succeeds and returns
* the identifier of the language that best supports the Windows console.
*
* <p><strong>Remarks</strong></p>
* <p>
* When a thread is created, the thread user interface language setting is empty and the user interface for
* the thread is displayed in the user-selected language. This function enables the application to change
Expand All @@ -4417,6 +4410,13 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
* a valid nonzero language identifier, the function sets a particular user interface language for the thread.
* </p>
*
* @param LangId Language identifier for the user interface language for the thread.
*
* @return Returns the input language identifier if successful.
* If the input identifier is nonzero, the function returns that value.
* If the language identifier is 0, the function always succeeds and returns
* the identifier of the language that best supports the Windows console.
*
* @see <a href="https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-setthreaduilanguage">SetThreadUILanguage</a>
*/
int SetThreadUILanguage(int LangId);
Expand Down Expand Up @@ -4446,9 +4446,9 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
* @param pulNumLanguages Pointer to the number of languages that the function has set in the thread preferred UI languages list.
* When the application specifies one of the filtering flags, the function must set this parameter to NULL.
*
* @return Returns TRUE if the function succeeds or FALSE otherwise.
* @return Returns {@code true} if the function succeeds or {@code false} otherwise.
*/
boolean SetThreadPreferredUILanguages(DWORD dwFlags, StringArray pwszLanguagesBuffer, ULONGByReference pulNumLanguages);
boolean SetThreadPreferredUILanguages(int dwFlags, String[] pwszLanguagesBuffer, IntByReference pulNumLanguages);

/**
* Returns the language identifier of the first user interface language for the current thread.
Expand Down
18 changes: 2 additions & 16 deletions contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java
Expand Up @@ -36,7 +36,6 @@
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.StringArray;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
import com.sun.jna.platform.win32.WinNT.HRESULT;
Expand Down Expand Up @@ -300,17 +299,6 @@ public static String getLastErrorMessage(int primaryLangId, int sublangId) {
.GetLastError(), primaryLangId, sublangId);
}

/**
* Sets the user interface language for the current thread using primary and sub-language identifiers.
*
* @param langId Language identifier.
*
* @return Returns the input language identifier if successful.
*/
public static int setThreadUILanguage(int langId) {
return Kernel32.INSTANCE.SetThreadUILanguage(langId);
}

/**
* Sets the thread preferred UI languages for the current thread.
*
Expand All @@ -319,10 +307,8 @@ public static int setThreadUILanguage(int langId) {
* @return Returns TRUE if the function succeeds or FALSE otherwise.
*/
public static boolean setThreadPreferredUILanguages(String[] languages) {
DWORD dwFlags = new DWORD(0);
StringArray pwszLanguagesBuffer = new StringArray(languages);
ULONGByReference pulNumLanguages = new ULONGByReference(new ULONG(languages.length));
return Kernel32.INSTANCE.SetThreadPreferredUILanguages(dwFlags, pwszLanguagesBuffer, pulNumLanguages);
IntByReference pulNumLanguages = new IntByReference(languages.length);
return Kernel32.INSTANCE.SetThreadPreferredUILanguages(0, languages, pulNumLanguages);
}

/**
Expand Down
Expand Up @@ -63,7 +63,6 @@
import com.sun.jna.NativeMappedConverter;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.StringArray;

import com.sun.jna.platform.win32.BaseTSD.SIZE_T;
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR;
Expand Down Expand Up @@ -2113,10 +2112,9 @@ public void testSetThreadUILanguage() {
}

public void testSetThreadPreferredUILanguages() {
WinDef.DWORD dwFlags = new WinDef.DWORD(0);
StringArray pwszLanguagesBuffer = (StringArray) StringArray.NULL;
WinDef.ULONGByReference pulNumLanguages = new WinDef.ULONGByReference();
boolean result = Kernel32.INSTANCE.SetThreadPreferredUILanguages(dwFlags, pwszLanguagesBuffer, pulNumLanguages);
String[] languages = {};
IntByReference pulNumLanguages = new IntByReference(languages.length);
boolean result = Kernel32.INSTANCE.SetThreadPreferredUILanguages(0, languages, pulNumLanguages);
assertTrue(result);
}

Expand Down
Expand Up @@ -171,16 +171,6 @@ public void testFormatMessageFromErrorCodeWithNonEnglishLocale() {
}
}

public void testSetThreadUILanguage() {
int langId = 0x0409; // English (United States)
int result = Kernel32Util.setThreadUILanguage(langId);
if (result == 0) {
int errorCode = Kernel32.INSTANCE.GetLastError();
fail("SetThreadUILanguage failed with error code " + errorCode);
}
assertEquals(langId, result);
}

public void testSetThreadPreferredUILanguages() {
String[] languages = {};
boolean result = Kernel32Util.setThreadPreferredUILanguages(languages);
Expand Down

0 comments on commit e935d9c

Please sign in to comment.