2 messages in net.java.dev.jna.usersRe: [jna-users] wnetaddconnection error
FromSent OnAttachments
Nadeema AjihilDec 18, 2007 12:17 am 
Daniel KaufmannDec 18, 2007 6:21 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] wnetaddconnection errorActions...
From:Daniel Kaufmann (Dani@hotmail.com)
Date:Dec 18, 2007 6:21:28 pm
List:net.java.dev.jna.users

DWORD should be mapped to int, in your structure you are mapping to long. You didn't sent the defintion of NetAddConnection2, but if you also mapped the parameter DWORD dwFlags to long dwFlags, you should fix that too. Thanks, Daniel

----- Original Message ----- From: "Nadeema Ajihil" <aji@morson.jp> To: <use@jna.dev.java.net> Sent: Tuesday, December 18, 2007 5:17 AM Subject: [jna-users] wnetaddconnection error

What I'm trying to do here is access a Windows server using Windows API function wnetaddconnection. I got my program to use the function but it kept getting the error 487 when connecting. Which is "Attempt to access invalid address." Now, I'm pretty sure I got the address correct. The same parameters were used with another Program written in powerbuilder and also uses the Windows API.

This is how the function looks like:

DWORD WNetAddConnection2( __in LPNETRESOURCE lpNetResource, __in LPCTSTR lpPassword, __in LPCTSTR lpUsername, __in DWORD dwFlags );

So I created my own Structure in Java:

public class NETRESOURCE extends Structure{ public long dwScope; public long dwType; public long dwDisplayType; public long dwUsage; public String lpLocalName; public String lpRemoteName; public String lpComment; public String lpProvider; }

The C looked like this:

typedef struct _NETRESOURCE { DWORD dwScope; DWORD dwType; DWORD dwDisplayType; DWORD dwUsage; LPTSTR lpLocalName; LPTSTR lpRemoteName; LPTSTR lpComment; LPTSTR lpProvider; } NETRESOURCE;

Then I called the function like this:

MPR mpr = MPR.INSTANCE; NETRESOURCE lp = new NETRESOURCE(); lp.dwType=0; lp.lpLocalName=null; lp.lpProvider=null; lp.lpRemoteName="\\\\valid\\address\\pramis"; int i = mpr.WNetAddConnection2A(lp, "password", "username", 0);

Any help would be appreciated. Please.