This s a re-post of a question from Tuesday that got in the wrong category. I've tried to include the responses as best I could.
ORIGINAL QUESTION >>>>
I've got a VB program that reads a database to find the location of a project, and then maps a Drive letter to an NT share. It works great in 95 (clients are 95, servers are NT), but I'm getting an error code 1326 when I try to run it on an NT client. I'm pretty sure I've narrowed it down to the way the password is handled, but I don't see any way around it. According to the Win32API help, the WNetAddConnection call can accept a NULL for the password, and thereby "use the default password". My problem is that the declare in the Library uses a String for the password, and I can't pass a NULL (which, of course is different than an empty string) If I use an empty string, the WIN32API help file says wNetAddConnection "uses no password"
The VB declare for WNetAddConnection:
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As Variant, ByVal lpszLocalName As String) As Long
My call to WNetAddConnection:
lResult = WNetAddConnection(sProjectPath, "", csDRIVE)
If I could just use a Variant for the password, all would be well, but I can't change the Library.
P.S. ( I am aware of the WNetAddConnection2 & 3 functions, but I don't think they would make any difference. They still have the same declares for the password)
ANSWER FROM ALAMO >>>>>
Rejected AnswerFrom: alamoDate: Tuesday, July 21 1998 - 11:12AM PDT Well, this should be in the VB area, but migth as well answer it here...
There are a number of ways to handle this. The easiest is to use vbNullString - this is a special value to signal VB to pass 0 rather than a real string.
So your call would be:
lResult = WNetAddConnection(sProjectPath, vbNullString, csDRIVE)
and your Declare would of course have the password as "ByVal lpszPassword As String" not as Variant.
The other way to handle this is to change your declaration to one VB will accept but which still calls the function in the identical manner:
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As Any, ByVal lpszLocalName As String) As Long
Now you could call either of the following and it would work:
lResult = WNetAddConnection(sProjectPath, 0&, csDRIVE)
lResult = WNetAddConnection(sProjectPath, "password", csDRIVE)
Hope this helps!
MY NEXT RESPONSE >>>>>
However, it didn't fix my problem. Now the error code I get is
#47 - Invalid address (I'm doing that from memory, so I may not have it right)
In any event, now my problem looks to be that VB won't accept a NULL for the password, which NT wants to use to just pick up the user's default password.
AND ALAMO's NEXT RESPONSE >>>>>>
>In any event, now my problem looks to be that VB won't accept a NULL for the password
Nope, the code I posted passes NULL for password. That's not your problem.
It's more likely that sProjectPath or csDRIVE are wrong, but you didn't post the portion of code which sets them. What are they?
FINALLY, MY LATEST >>>>>
I should have worded my response more carefully.
I should have said:
It looks like the VB call to WNetAddConnection can't handle a NULL as password. The sProjectPath and csDRIVE have been working fine under 95 for months. It's only when I mess with the password parameter that I run into these problems.
I also should not have tried to remeber the error code. The actual error code is #487 ( I had guessed 47). This WIN32API.TXT file I have describes this error as:
' Attempt to access invalid address.
Public Const ERROR_INVALID_ADDRESS = 487&
Sorry for the long post, and Thanks for any help.