Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automating a network connection
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00434820
Message ID:
00434832
Views:
13
>I have the following function in my startup program (I pulled it off the thread awile ago) that is supposed to estabish a network connection if the user isn't already connected. It works fine in test (when I manually disconnect from the drive and run the startup.prg). However, once I compile the EXE and run it (after disconnecting from the drive) I get a FILE NOT FOUND error. The first line of code in the launch program is :
>
>if ConnectToDrive()=.f.
> return .f.
>endif
>
>
>
>***********************
>function ConnectToDrive
>***********************
>* Already connected
>if drivetype("y")=4
> return .t.
>endif
>
>* Drive doesn't exist
>if drivetype("y")=1
> declare integer WNetAddConnection in "mpr.dll" ;
> string cRemoteName, ;
> string cPassword, ;
> string cLocalName
>
> cResource = "\\server\directory"
> cPassword = ""
> cDriveLetter = "y:"
>
> * Established connection.
> if WNetAddConnection(cResource, cPassword, cDriveLetter)=0
> return .t.
> endif
>endif
>return .f.

I've used this function quite a bit in the past. Off the top of my head, my declaration and execution of the call look like this.
DECLARE INTEGER WNetAddConnection IN Win32API;
  STRING @lpszRemoteName, STRING @lpszPassword, STRING @lpszLocalName
lnresult = WNetAddConnection(@cResource, 0, @cDriveLetter)
IOW, the strings should be passed by reference. To pass a null pointer for the password, use 0 rather than an empty string.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform