-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong parameter type in Mpr WNetUseConnection #1010
Comments
According to the docs, you need to provide a buffer to be filled in (make
sure it's at least as large as lpRemoteName). PointerByReference only
gives you a buffer the size of a pointer. You might be better off with
byte[] and using Native.toString(byte[]) to convert it to String.
lpAccessName
… Pointer to a buffer that receives system requests on the connection. This
parameter can be NULL.
If this parameter is specified, and the lpLocalName member of the
NETRESOURCE structure specifies a local device, this buffer receives the
local device name. If lpLocalName does not specify a device and the
network requires a local device redirection, or if the CONNECT_REDIRECT
value is set, this buffer receives the name of the redirected local device.
Otherwise, the name copied into the buffer is that of a remote resource.
If specified, this buffer must be at least as large as the string pointed
to by the lpRemoteName member.
On Mon, Sep 10, 2018 at 12:43 PM Nikola Sprljan ***@***.***> wrote:
I use JNA 4.3.0, but use of Mpr lib should be the same in the latest.
The following function:
WNetUseConnection(HWND hwndOwner, NETRESOURCE lpNETRESOURCE, String
lpPassword, String lpUserID, int dwFlags, PointerByReference lpAccessName,
IntByReference lpBufferSize, IntByReference lpResult);
has PointerByReference type used for parameter lpAccessName, but it seems
to me it should be char[].
MSDN WNetUseConnection() has it as LPSTR lpAccessName
In my implementation only char[] works, while PointerByReference does not
(getValue().getString(0)). I guess there could be some way to dance around
the returned PointerByReference to get the string out of it, but I haven't
found it.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1010>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAuMrc9X5HyY48_2yxKE2tEa4mgbjudtks5uZpbBgaJpZM4Whxie>
.
|
I would just use a Memory object - this is the adaption for the Memory lpAccessName;
if(DEFAULT_OPTIONS==UNICODE_OPTIONS) {
lpAccessName = new Memory((WinDef.MAX_PATH + 1) * Native.WCHAR_SIZE);
} else {
lpAccessName = new Memory(WinDef.MAX_PATH + 1);
}
IntByReference lpAccessNameSize = new IntByReference(WinDef.MAX_PATH);
assertEquals(WinError.ERROR_SUCCESS, Mpr.INSTANCE.WNetUseConnection(null, resource, null, null, 0, lpAccessName, lpAccessNameSize, null));
System.out.println("Size: " + lpAccessNameSize.getValue());
if(DEFAULT_OPTIONS==UNICODE_OPTIONS) {
System.out.println("lpAccessName: " + lpAccessName.getWideString(0));
} else {
System.out.println("lpAccessName: " + lpAccessName.getString(0));
} This demonstrates the code necessary, so that both calling variants are supported. |
matthiasblaesing
added a commit
to matthiasblaesing/jna
that referenced
this issue
Sep 10, 2018
…`c.s.j.p.win32.Mpr#WNetUseConnection
Yes, that works and is much better than a plain char/byte array - thanks Matthias! |
matthiasblaesing
added a commit
that referenced
this issue
Sep 11, 2018
[#1010] Fix binding of `lpAccessName` parameter of `c.s.j.p.win32.Mpr#WNetUseConnection
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use JNA 4.3.0, but use of Mpr lib should be the same in the latest.
The following function:
WNetUseConnection(HWND hwndOwner, NETRESOURCE lpNETRESOURCE, String lpPassword, String lpUserID, int dwFlags, PointerByReference lpAccessName, IntByReference lpBufferSize, IntByReference lpResult);
has
PointerByReference
type used for parameterlpAccessName
, but it seems to me it should bechar[]
.MSDN WNetUseConnection() has it as
LPSTR lpAccessName
In my implementation only char[] works, while PointerByReference does not (getValue().getString(0)). I guess there could be some way to dance around the returned PointerByReference to get the string out of it, but I haven't found it.
The text was updated successfully, but these errors were encountered: