Page 2 of 2

Re: Vista - making network connections

Posted: Thu Feb 17, 2011 6:10 pm
by mikejs
Just trying to get this working on pb 4.51, and I run into a compile error. I'm using the following code, copied and pasted from earlier in the thread:

Code: Select all

Procedure xWNetCancelConnection(DriveLetter.s,force.l)
 
  ;/ Driveletter : Ex F:
  ;/ Force = #True or #False ( Deconnect when file is in use )
  ;/ Return 1 if success or 0 if fail
 
  OpenLibrary(0,"Mpr.dll")
  Retour=CallFunction(0,"WNetCancelConnectionA",DriveLetter,force)
  CloseLibrary(0)
  ProcedureReturn Retour
EndProcedure

Procedure xWNetAddConnection(UserName.s,Password.s,ShareName.s,DriveLetter.s,Persistant.l)
  ;/ Username / Password
  ;/ Sharename : \\Server\Share
  ;/ DriveLetter : F:
  ;/ Persistant : #True or #False
  ;/ Return 1 if success or 0 if fail
 
  ;CallDebugger
 
  lpNetResource.NETRESOURCE
  lpNetResource\dwType=1 ; RESOURCETYPE_DISK
  lpNetResource\lpLocalName=@DriveLetter
  lpNetResource\lpRemoteName=@ShareName
 
  OpenLibrary(0,"Mpr.dll")
  Retour=CallFunction(0,"WNetAddConnection2A",lpNetResource,Password,UserName,Persistant)
  CloseLibrary(0)
  ProcedureReturn Retour
EndProcedure

result = xWNetCancelConnection("x:",#True)
MessageRequester("Cancel result: ","result: " + Str(result),#PB_MessageRequester_Ok)

result = xWNetAddConnection("testuser","Welkom01","\\server02\bginfo","x:",#True)
MessageRequester("Map result: ","result: " + Str(result),#PB_MessageRequester_Ok)
Compiling this fails on the CallFunction line with "Line 8: Bad parameter type, number expected instead of string."

If I comment that out, the other CallFunction line generates the same error. Has the behaviour of CallFunction changed?

Any suggestions on how to call WNetAddConnection2A and similar functions?

Re: Vista - making network connections

Posted: Fri Feb 18, 2011 11:24 am
by mikejs
Never mind - I have something working now using prototypes, which seems to be how you're supposed to do things these days:

Code: Select all

Prototype.l ProtoCancelConnection(name$,force.l=#False)
Prototype.l ProtoAddConnection(*lpnr,pass$,user$,flags.l=0)

mpr.l=OpenLibrary(#PB_Any, "Mpr.dll")
If mpr
  CancelConnection.ProtoCancelConnection=GetFunction(mpr, "WNetCancelConnectionA")
  AddConnection.ProtoAddConnection=GetFunction(mpr, "WNetAddConnection2A")

  drive$="j:"
  share$="\\server\share"
  user$="domain\user"
  pass$="password"
  
  lpNetResource.NETRESOURCE
  lpNetResource\dwType=1 ; RESOURCETYPE_DISK
  lpNetResource\lpLocalName=@drive$
  lpNetResource\lpRemoteName=@share$
  
  result = CancelConnection(drive$,#True)
  MessageRequester("Cancel result: ","result: " + Str(result),#PB_MessageRequester_Ok)
  
  result = AddConnection(@lpNetResource,pass$,user$,0)
  MessageRequester("Map result: ","result: " + Str(result),#PB_MessageRequester_Ok)
  
  CloseLibrary(mpr)
EndIf

Re: Vista - making network connections

Posted: Fri Feb 18, 2011 4:00 pm
by Rook Zimbabwe
which version of VISTA (and which FIREWALL software)?