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.