I was able to make it work by modifying code as follows:
public static interface TestNative extends Library
{
int get(int length, Pointer buffer);
}
Pointer was obtained by:
Pointer bfPtr = Native.getDirectBufferPointer(buffer); // buffer points to ByteBuffer allocated as direct NIO buffer.