January 1, 2005

WinTask - WNetGetConnection

'
' WNetGetConnection - get the name of the network resource associated with a local device
'

' Author: Joe Strazzere
'

' WNetGetConnection(
'  LPCTSTR lpLocalName,  // local name
'  LPTSTR lpRemoteName,  // buffer for remote name
'  LPDWORD lpnLength     // buffer size
');

 

dim ptr1 as unsigned
dim ptr2 as unsigned
dim ptr3 as unsigned

 

ptr1=allocate(255)
ptr2=allocate(255)
ptr3=allocate(4)

 

local$ ="I:"     ' the local drive name
remote$="not found"  ' where the remote name goes

pokestring(ptr1,local$,1)
pokestring(ptr2,"                                                                ",1)
pokeinteger(ptr3,64,4)

 

ret = External("mpr","WNetGetConnectionA", ptr1, ptr2, ptr3)
remote$=peekstring$(ptr2)

 

If ret = 0 then
    msgbox(local$+" is really "+remote$,,"WNetGetConnection")
else
    msgbox("An error occurred trying to find "+local$+"  Return Code="+str$(ret))
EndIf