LLamada a WNetGetConnectionA no me funciona

Post Reply
Carlos Mora

LLamada a WNetGetConnectionA no me funciona

Post by Carlos Mora »

Amigos,
no se que estoy haciendo mal, a ver si alguien me dice donde meto la pata.
Quiero saber el nombre de red de un disco. Para eso esta la funcion WNetGetConnectionA en mpr.dll
La declaracion segun los manuales de la API son

Code: Select all

Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
por lo que la declaro en mi prg de HArbour + FW

Code: Select all

dll32 static function ;
      WNetGetCon( @cLocalName AS STRING, @cRemoteName AS STRING, nLength AS LONG ) ;
      AS LONG PASCAL FROM "WNetGetConnectionA" ;
      Lib "mpr.dll"
Y luego la llamo

Code: Select all

function GetNetDriveName( cDrive )
local x := 0
local cName := Space( 128 )

cDrive := Left( cDrive, 3 )+Chr(0)
x:= WNetGetCon( @cDrive, @cName, 128 )
debug x, cDrive, Len(cname)
If x != 0
   cDrive := Left( cDrive, 2 )+Chr(0)
   x:= WNetGetCon( @cDrive, @cName, 128 )
   debug x, cDrive, Len(cname)
   If x != 0
      cDrive := Left( cDrive, 1 )+Chr(0)
      x:= WNetGetCon( @cDrive, @cName, 128 )
      debug x, cDrive, Len(cname)
   EndIf
EndIf
Asi, a lo bruto, porque me falla!
el comando debug me hace un Outputdebugstring de cada parametro en el dbwin
x siempre me trae el codigo de error 487
que en winerror.h dice:

Code: Select all

//
// MessageId: ERROR_INVALID_ADDRESS
//
// MessageText:
//
//  Attempt to access invalid address.
//
#define ERROR_INVALID_ADDRESS            487L
Es decir que hay algun problma con la declaracion o el pase de parametros o algo, pero no me doy cuenta.

Alguna idea?

Saludos
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Carlos,

Pruébalo así:

Code: Select all

dll32 static function ; 
      WNetGetCon( cLocalName AS STRING, cRemoteName AS STRING, nLength AS LONG ) ; 
      AS LONG PASCAL FROM "WNetGetConnectionA" ; 
      Lib "mpr.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply