I'm trying to learn how to work with windows native code from Java. For this I use the JNA library. I'm just starting to learn how to work with this library and ran into this problem. The ADsGetObject function call fails. Perhaps I did not fully understand how to convert data types and do not use them correctly.
Here is my code:
import com.sun.jna.Native;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Guid.REFIID;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.platform.win32.WinNT.HRESULT;
public class GetUserAttribute {
public static void main(String[] args) {
getUser("CN=Scaner,OU=Services,DC=my,DC=domain");
}
public interface Activeds extends StdCallLibrary {
Activeds INSTANCE = (Activeds) Native.load("Activeds", Activeds.class);
HRESULT ADsGetObject(WString lpszPathName, REFIID riid, PointerByReference ppObject);
}
public static void getUser(String dn) {
WString userDN = new WString(dn);
REFIID riid = new REFIID();
PointerByReference ppObject = new PointerByReference();
HRESULT hr = Activeds.INSTANCE.ADsGetObject(userDN,riid,ppObject);
System.out.println(hr);
}
When executed, hr is 0x80004005 (Unspecified error). I would be grateful for any hints on what I'm doing wrong and maybe for an example of a working code.
Here is the code on VBS that works correctly. Would like to "translate" it into Java code:
Dim strUserDN = "CN=Scaner,OU=Services,DC=my,DC=domain"
set objUser = GetObject("LDAP://" & strUserDN)
Wscript.echo objUser.cn