Skip to content
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

Closed
nsprljan opened this issue Sep 10, 2018 · 3 comments
Closed

Wrong parameter type in Mpr WNetUseConnection #1010

nsprljan opened this issue Sep 10, 2018 · 3 comments

Comments

@nsprljan
Copy link

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.

@twall
Copy link
Contributor

twall commented Sep 10, 2018 via email

@matthiasblaesing
Copy link
Member

I would just use a Memory object - this is the adaption for the MprTest for testing:

            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
@nsprljan
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants