Re:Using WNetAddConnection2 under win95
Here is one built on AddConnection3
It could be a lot smoother, but anyway
Be careful to read delphi's declaration of the function
and not just the win32 documentation. Delphi
sometimes declares the netresources structure as a
parameter where the documentation reads a pointer
to the structure.
Function AddConnection3(WinHandle : Thandle; LoginName, Password, UNC,
Drive :String) : Boolean;
Type
TmyResource = TNetResource;
Const
ToNull = '';
var
myResource : TmyResource;
PtrPassword : PChar;
PtrLogin : PChar;
ConnectBits : DWord;
passedlogin : string[30];
passedpword : string[30];
passedunc : string[255];
PassedLocal : string[2];
myResbufsize : integer;
Yeah : integer;
Nope : DWord;
begin
passedlogin := LoginName;
passedpword := Password;
passedunc := UNC;
passedlocal := Drive;
PtrPassword := strAlloc(31);
StrPCopy(PtrPassword, passedpword);
PtrLogin := strAlloc(31);
StrPCopy(PtrLogin, passedlogin);
ConnectBits := 0;
myResource.dwtype := ResourceType_Disk;
myResource.dwScope := 0;
MyResource.dwDisplayType := 0;
MyResource.dwUsage := 1;
myResource.lpLocalName := StrAlloc(2);
StrPCopy(myResource.lpLocalName, ToNull);
myResource.lpRemoteName := StrAlloc(256);
StrPCopy(myResource.lpRemoteName, Passedunc);
myResource.lpProvider := StrAlloc(2);
StrPCopy(myResource.lpProvider, ToNull);
myResource.lpComment := StrAlloc(2);
StrPCopy(myResource.lpComment, ToNull);
Yeah := WNetAddConnection3(WinHandle, myResource, PtrPassword,
PtrLogin, ConnectBits);
If Yeah = NO_ERROR then
Result := true
Else
Begin
Nope := GetLastError;
If Nope = Error_AlreadyConnected
then
Result := True
Else
Begin //resolve Error
Result := False;
End;
End;
StrDispose(PtrPassword);
StrDispose(PtrLogin);
StrDispose(Myresource.lpLocalName);
StrDispose(MyResource.lpRemoteName);
StrDispose(MyResource.lpProvider);
StrDispose(MyResource.lpComment);
End;
Jonathon C Page <j...@vaxxine.com> wrote in article
<58n87k$...@alpha.vaxxine.com>...
Quote
> Greetings All
> Has anyone out there used WNetAddConnection2 in Delphi 2.0
> If so, could you please post a portion of code, I cant seem to get
> that dang NetResource portion working, keeps giving me something to
> the idea that the passed variables must be the same as the defined
> variables or something...
> Thanks in Advance
> Jonathon C Page
> Jonathon C Page.
> Sr Network Support Analyst
> The Regional Municipality of Niagara
> Phone: (905)685-1571 Ext 439
> Fax: (905)687-4977