Hello,
I am using JNA version 5.0.0 to invoke a Win32 API part of NetAPI32.dll
The function prototype for the API looks like this :
DWORD _stdcall I_NetLogonControl2( LPCWSTR ServerName, DWORD FunctionCode, DWORD QueryLevel, LPBYTE Data, LPBYTE *Buffer ); [0]
For the FunctionCode (NETLOGON_CONTROL_TC_VERIFY) I am using, Data is expected to be an address of WCHAR* string that is null terminated (the data type is LPWSTR *).
While the Instance is declared as follows in my code
static interface NetAPI extends StdCallLibrary {
int I_NetLogonControl2( WString serverName, int functionCode, int queryLevel, PointerByReference data, PointerByReference buffer);
NetAPI INSTANCE = (NetAPI) Native.loadLibrary("netapi32", NetAPI.class, W32APIOptions.DEFAULT_OPTIONS);
}
The call to the function is made using the following code snippet:
String domainName = new String("
fabrikam.com");
PointerByReference buffer = new PointerByReference();
Pointer ptr = new Memory((domainName.length() + 1) * Native.WCHAR_SIZE);
ptr.setWideString(0, domainName);
PointerByReference data = new PointerByReference();
data.setPointer(ptr);
int i = NetAPI.INSTANCE.I_NetLogonControl2(null, 10, 2, data, buffer);
It throws an IMA exception :
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:425)
at com.sun.jna.Function.invoke(Function.java:360)
The exception is being thrown while accessing the second last argument - 'data'. What am I missing ? How do I go about debugging this issue.
Instead of SetWideString, I have tried to manually set the memory in ptr to the expected values directly byte-by-byte it didn't make any difference.
Any suggestions will help.
Many thanks!