Vista - making network connections

Just starting out? Need help? Post your questions and find answers here.
mikejs
Enthusiast
Enthusiast
Posts: 175
Joined: Thu Oct 21, 2010 9:46 pm

Re: Vista - making network connections

Post 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?
mikejs
Enthusiast
Enthusiast
Posts: 175
Joined: Thu Oct 21, 2010 9:46 pm

Re: Vista - making network connections

Post 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
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Vista - making network connections

Post by Rook Zimbabwe »

which version of VISTA (and which FIREWALL software)?
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply