Skip to content

Commit e935d9c

Browse files
committed
Fix java doc, change parameter types and update CHANGES.md
1 parent 2e96df4 commit e935d9c

File tree

5 files changed

+16
-41
lines changed

5 files changed

+16
-41
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Next Release (5.14.0)
77

88
Features
99
--------
10+
* [#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).
1011

1112
Bug Fixes
1213
---------

contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.sun.jna.LastErrorException;
2727
import com.sun.jna.Native;
2828
import com.sun.jna.Pointer;
29-
import com.sun.jna.StringArray;
3029
import com.sun.jna.ptr.IntByReference;
3130
import com.sun.jna.ptr.PointerByReference;
3231
import com.sun.jna.win32.StdCallLibrary;
@@ -4399,13 +4398,7 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
43994398
* to use on the Windows console.
44004399
* </p>
44014400
*
4402-
* @param LangId Language identifier for the user interface language for the thread.
4403-
*
4404-
* @return Returns the input language identifier if successful.
4405-
* If the input identifier is nonzero, the function returns that value.
4406-
* If the language identifier is 0, the function always succeeds and returns
4407-
* the identifier of the language that best supports the Windows console.
4408-
*
4401+
* <p><strong>Remarks</strong></p>
44094402
* <p>
44104403
* When a thread is created, the thread user interface language setting is empty and the user interface for
44114404
* the thread is displayed in the user-selected language. This function enables the application to change
@@ -4417,6 +4410,13 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
44174410
* a valid nonzero language identifier, the function sets a particular user interface language for the thread.
44184411
* </p>
44194412
*
4413+
* @param LangId Language identifier for the user interface language for the thread.
4414+
*
4415+
* @return Returns the input language identifier if successful.
4416+
* If the input identifier is nonzero, the function returns that value.
4417+
* If the language identifier is 0, the function always succeeds and returns
4418+
* the identifier of the language that best supports the Windows console.
4419+
*
44204420
* @see <a href="https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-setthreaduilanguage">SetThreadUILanguage</a>
44214421
*/
44224422
int SetThreadUILanguage(int LangId);
@@ -4446,9 +4446,9 @@ Pointer VirtualAllocEx(HANDLE hProcess, Pointer lpAddress, SIZE_T dwSize,
44464446
* @param pulNumLanguages Pointer to the number of languages that the function has set in the thread preferred UI languages list.
44474447
* When the application specifies one of the filtering flags, the function must set this parameter to NULL.
44484448
*
4449-
* @return Returns TRUE if the function succeeds or FALSE otherwise.
4449+
* @return Returns {@code true} if the function succeeds or {@code false} otherwise.
44504450
*/
4451-
boolean SetThreadPreferredUILanguages(DWORD dwFlags, StringArray pwszLanguagesBuffer, ULONGByReference pulNumLanguages);
4451+
boolean SetThreadPreferredUILanguages(int dwFlags, String[] pwszLanguagesBuffer, IntByReference pulNumLanguages);
44524452

44534453
/**
44544454
* Returns the language identifier of the first user interface language for the current thread.

contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.sun.jna.Memory;
3737
import com.sun.jna.Native;
3838
import com.sun.jna.Pointer;
39-
import com.sun.jna.StringArray;
4039
import com.sun.jna.platform.win32.WinNT.HANDLE;
4140
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
4241
import com.sun.jna.platform.win32.WinNT.HRESULT;
@@ -300,17 +299,6 @@ public static String getLastErrorMessage(int primaryLangId, int sublangId) {
300299
.GetLastError(), primaryLangId, sublangId);
301300
}
302301

303-
/**
304-
* Sets the user interface language for the current thread using primary and sub-language identifiers.
305-
*
306-
* @param langId Language identifier.
307-
*
308-
* @return Returns the input language identifier if successful.
309-
*/
310-
public static int setThreadUILanguage(int langId) {
311-
return Kernel32.INSTANCE.SetThreadUILanguage(langId);
312-
}
313-
314302
/**
315303
* Sets the thread preferred UI languages for the current thread.
316304
*
@@ -319,10 +307,8 @@ public static int setThreadUILanguage(int langId) {
319307
* @return Returns TRUE if the function succeeds or FALSE otherwise.
320308
*/
321309
public static boolean setThreadPreferredUILanguages(String[] languages) {
322-
DWORD dwFlags = new DWORD(0);
323-
StringArray pwszLanguagesBuffer = new StringArray(languages);
324-
ULONGByReference pulNumLanguages = new ULONGByReference(new ULONG(languages.length));
325-
return Kernel32.INSTANCE.SetThreadPreferredUILanguages(dwFlags, pwszLanguagesBuffer, pulNumLanguages);
310+
IntByReference pulNumLanguages = new IntByReference(languages.length);
311+
return Kernel32.INSTANCE.SetThreadPreferredUILanguages(0, languages, pulNumLanguages);
326312
}
327313

328314
/**

contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import com.sun.jna.NativeMappedConverter;
6464
import com.sun.jna.Platform;
6565
import com.sun.jna.Pointer;
66-
import com.sun.jna.StringArray;
6766

6867
import com.sun.jna.platform.win32.BaseTSD.SIZE_T;
6968
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR;
@@ -2113,10 +2112,9 @@ public void testSetThreadUILanguage() {
21132112
}
21142113

21152114
public void testSetThreadPreferredUILanguages() {
2116-
WinDef.DWORD dwFlags = new WinDef.DWORD(0);
2117-
StringArray pwszLanguagesBuffer = (StringArray) StringArray.NULL;
2118-
WinDef.ULONGByReference pulNumLanguages = new WinDef.ULONGByReference();
2119-
boolean result = Kernel32.INSTANCE.SetThreadPreferredUILanguages(dwFlags, pwszLanguagesBuffer, pulNumLanguages);
2115+
String[] languages = {};
2116+
IntByReference pulNumLanguages = new IntByReference(languages.length);
2117+
boolean result = Kernel32.INSTANCE.SetThreadPreferredUILanguages(0, languages, pulNumLanguages);
21202118
assertTrue(result);
21212119
}
21222120

contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java

-10
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,6 @@ public void testFormatMessageFromErrorCodeWithNonEnglishLocale() {
171171
}
172172
}
173173

174-
public void testSetThreadUILanguage() {
175-
int langId = 0x0409; // English (United States)
176-
int result = Kernel32Util.setThreadUILanguage(langId);
177-
if (result == 0) {
178-
int errorCode = Kernel32.INSTANCE.GetLastError();
179-
fail("SetThreadUILanguage failed with error code " + errorCode);
180-
}
181-
assertEquals(langId, result);
182-
}
183-
184174
public void testSetThreadPreferredUILanguages() {
185175
String[] languages = {};
186176
boolean result = Kernel32Util.setThreadPreferredUILanguages(languages);

0 commit comments

Comments
 (0)