Jump to content
Excelsior Forums
Sign in to follow this  
KenMacD

wnetAddConnection2A network name cannot be found

Recommended Posts

Hello.

I'm trying to make a call to: mpr.dll:wnetAddConnection2

I keep getting back error code 67. "The Network name cannot be found"

From MSDN this function's signature is: http://tinyurl.com/4b5uq

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

The lpNetResource is a structure: http://tinyurl.com/4zflz

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

My NetResource structure looks like:

class NetResource extends com.excelsior.xFunction.Structure
{
   int scope;
   int type;
   int displayType;
   int usage;
   com.excelsior.xFunction.Pointer localName;
   com.excelsior.xFunction.Pointer remoteName;
   com.excelsior.xFunction.Pointer comment;
   com.excelsior.xFunction.Pointer provider;

   public NetResource() {}

   public String
   defineLayout()
   {
       return "int scope, int type, int displayType, int usage, char* localName, char* remoteName, char* comment," +
           " char* provider";
   }
}

The code that is trying to call the function is:

    String path = "\\\\server\\share";
       String username = "Administrator";
       String password = "........";

       NetResource netResource = new NetResource();
       netResource.scope = 2; // GlobalNet
       netResource.type = 0; // Any
       netResource.displayType = 4; // File
       netResource.usage = 1; // Connectable
       netResource.remoteName =
           new com.excelsior.xFunction.Argument(path, com.excelsior.xFunction.Argument.CSTRING).createPointer();
       netResource.localName = com.excelsior.xFunction.Pointer.NULL;
       netResource.comment = com.excelsior.xFunction.Pointer.NULL;
       netResource.provider = com.excelsior.xFunction.Pointer.NULL;

       com.excelsior.xFunction.xFunction wnetAddConnection2 = new com.excelsior.xFunction.xFunction("mpr",
           "int WNetAddConnection2A(Provisor.Win32.NetResource*, CSTRING, CSTRING, int)");
       com.excelsior.xFunction.Argument args[] = new com.excelsior.xFunction.Argument[4];
       args[0] = com.excelsior.xFunction.Pointer.createPointerTo(netResource);
       args[1] = new com.excelsior.xFunction.Argument(password, com.excelsior.xFunction.Argument.CSTRING);
       args[2] = new com.excelsior.xFunction.Argument(username, com.excelsior.xFunction.Argument.CSTRING);
       args[3] = com.excelsior.xFunction.Argument.create("int", new Integer(options.toInt()));

       int ret = ((Integer) wnetAddConnection2.invoke(args)).intValue();
       if(!ret==0)
       {
           System.err.println(getErrorMessage(ret));
       }

Does anyone have any idea's on why this will not work? It appears to work fine with these values in VBScript.

Thanks,

Kenny

Share this post


Link to post
Share on other sites

As far as I can understand, LPCTSTR is just a C string, so it shall be mapped to CSTRING but not to CSTRING*. See sample9 for example of strings as fields in structures.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×