Skip to content

Commit 6ac2404

Browse files
committed
Add RegConnectRegistry to Advapi32 mappings
1 parent ba92069 commit 6ac2404

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

+33
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,39 @@ boolean GetTokenInformation(HANDLE tokenHandle,
854854
int RegOpenKeyEx(HKEY hKey, String lpSubKey, int ulOptions,
855855
int samDesired, HKEYByReference phkResult);
856856

857+
/**
858+
* Establishes a connection to a predefined registry key on another
859+
* computer.
860+
* @param lpMachineName
861+
* The name of the remote computer. The string has
862+
* the following form:<br />
863+
* <pre><code>\\computername</code></pre>
864+
* The caller must have access to the remote computer or the
865+
* function fails.<br />
866+
* If this parameter is <c>null</c>, the local computer name
867+
* is used.
868+
* @param hKey
869+
* A predefined registry handle. This parameter can be one of
870+
* the following predefined keys on the remote computer.<br />
871+
* <ul>
872+
* <li>{@link WinReg#HKEY_LOCAL_MACHINE}</li>
873+
* <li>{@link WinReg#HKEY_PERFORMANCE_DATA}</li>
874+
* <li>{@link WinReg#HKEY_USERS}</li>
875+
* </ul>
876+
* @param phkResult
877+
* A pointer to a variable that receives a key handle
878+
* identifying the predefined handle on the remote computer.
879+
* @return If the function succeeds, the return value is
880+
* {@link WinError#ERROR_SUCCESS}.<br />
881+
* If the function fails, the return value is a nonzero error code
882+
* defined in Winerror.h. You can use the
883+
* {@link Native#getLastError} method to get a generic description
884+
* of the error.
885+
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724840.aspx">RegConnectRegistry function (Windows)</a>
886+
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724836.aspx">Predefined Keys (Windows)</a>
887+
*/
888+
int RegConnectRegistry(String lpMachineName, HKEY hKey, HKEYByReference phkResult);
889+
857890
/**
858891
* The RegQueryValueEx function retrieves the type and data for a specified
859892
* value name associated with an open registry key.

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

+8
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,14 @@ public void testRegOpenKeyEx() {
492492
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
493493
}
494494

495+
public void testRegConnectRegistry() {
496+
HKEYByReference phkResult = new HKEYByReference();
497+
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegConnectRegistry(
498+
"\\\\localhost", WinReg.HKEY_LOCAL_MACHINE, phkResult));
499+
assertTrue(WinBase.INVALID_HANDLE_VALUE != phkResult.getValue());
500+
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phkResult.getValue()));
501+
}
502+
495503
public void testRegQueryValueEx() {
496504
HKEYByReference phKey = new HKEYByReference();
497505
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(

0 commit comments

Comments
 (0)