Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Long path don't work in Novell's VBFLINFO sample

Status
Not open for further replies.

bjwade62

Programmer
Oct 31, 2002
15
US
I'm using VBFLINFO from Novell (see below) with no modifications other than using
my server and a file on it.

There seems to be some sort of limit to the "Full file
name including path:". I can type as many characters as I
want but it doesn't like longer file names. Shorter (less
characters) ones work fine.

The documentation says "This code is written to work
properly only in DOS name space. It requires some changes
for other name spaces (like LONG...)." File attached.

Can anyone help?

Thanks,
Bernie Wade


'================================================================
'Copyright ® 2000 Novell, Inc. All Rights Reserved.
'
' With respect to this file, Novell hereby grants to Developer a
' royalty-free, non-exclusive license to include this sample code
' and derivative binaries in its product. Novell grants to Developer
' worldwide distribution rights to market, distribute or sell this
' sample code file and derivative binaries as a component of
' Developer 's product(s). Novell shall have no obligations to
' Developer or Developer's customers with respect to this code.
'
'DISCLAIMER:
'
' Novell disclaims and excludes any and all express, implied, and
' statutory warranties, including, without limitation, warranties
' of good title, warranties against infringement, and the implied
' warranties of merchantibility and fitness for a particular purpose.
' Novell does not warrant that the software will satisfy customer's
' requirements or that the licensed works are without defect or error
' or that the operation of the software will be uninterrupted.
' Novell makes no warranties respecting any technical services or
' support tools provided under the agreement, and disclaims all other
' warranties, including the implied warranties of merchantability and
' fitness for a particular purpose.
'
'================================================================
'
' Project: VBFLINFO
'
' This sample code demonstrates how to read extended file
' info using DLL API call NWIntScanExtendedInfo().
' User should already be autenticated to the server.
' This code is written to work properly only in DOS name space.
' It requires some changes for other name spaces (like LONG...).
' For keeping the code simple and readable
' only very basic error handling is implemented.
'
' Programmers:
'
' Ini Who Firm
' ------------------------------------------------------------------
' RLE Rostislav Letos Novell DeveloperNet Labs
'
' History:
'
' When Who What
' ------------------------------------------------------------------
' 2000 August RLE Initial code
'=====================================================================
'
Option Explicit

Private Const NWCC_OPEN_LICENSED = &H1
Private Const NWCC_OPEN_UNLICENSED = &H2

Private Const NWCC_NAME_FORMAT_BIND = &H2
Private Const NWCC_NAME_FORMAT_NDS_TREE = &H8

Private Const NWCC_TRAN_TYPE_IPX = &H1
Private Const NWCC_TRAN_TYPE_WILD = &H8000

Private Type NW_EXT_FILE_INFO
sequence As Long
parent As Long
attributes As Long
uniqueID As Byte
flags As Byte
nameSpace As Byte
nameLength As Byte
fileName(11) As Byte
creationDateAndTime As Long
ownerID As Long
lastArchiveDateAndTime As Long
lastArchiverID As Long
updateDateAndTime As Long
lastUpdatorID As Long
dataForkSize As Long
dataForkFirstFAT As Long
nextTrusteeEntry As Long
reserved(35) As Byte
inheritedRightsMask As Integer
lastAccessDate As Integer
deletedFileTime As Long
deletedDateAndTime As Long
deletorID As Long
reserved2(15) As Byte
otherForkSize(1) As Long
End Type

Private Type VERSION_INFO
serverName(47) As Byte
fileServiceVersion As Byte
fileServiceSubVersion As Byte
maximumServiceConnections As Integer
connectionsInUse As Integer
maxNumberVolumes As Integer
revision As Byte
SFTLevel As Byte
TTSLevel As Byte
maxConnectionsEverUsed As Integer
accountVersion As Byte
VAPVersion As Byte
queueVersion As Byte
printVersion As Byte
virtualConsoleVersion As Byte
restrictionLevel As Byte
internetBridge As Byte
reserved(59) As Byte
End Type

Private Declare Function NWCallsInit Lib "calwin32" _
(reserved1 As Byte, reserved2 As Byte) As Long

Private Declare Function NWCCOpenConnByName Lib "clxwin32" _
(ByVal startConnHandle As Long, ByVal name As Long, _
ByVal nameFormat As Long, ByVal openState As Long, _
ByVal tranType As Long, pConnHandle As Long) As Long

Private Declare Function NWCCCloseConn Lib "clxwin32" _
(ByVal connHandle As Long) As Long

Private Declare Function NWAllocTemporaryDirectoryHandle Lib "calwin32" _
(ByVal conn As Long, ByVal dirHandle As Byte, _
ByVal dirPath As Long, newDirHandle As Byte, _
rightsMask As Byte) As Long

Private Declare Function NWDeallocateDirectoryHandle Lib "calwin32" _
(ByVal conn As Long, ByVal dirHandle As Byte) As Long

Private Declare Function NWIntScanExtendedInfo Lib "calwin32" _
(ByVal conn As Long, ByVal dirHandle As Byte, ByVal attrs As Byte, _
iterHandle As Long, ByVal searchPattern As String, _
fileInfo As NW_EXT_FILE_INFO, ByVal augmentFlag As Integer) As Long

Private Declare Function NWGetFileServerVersionInfo Lib "calwin32" _
(ByVal conn As Long, versBuffer As VERSION_INFO) As Long

Private Declare Function NWGetObjectName Lib "calwin32" _
(ByVal conn As Long, ByVal objID As Long, _
ByVal objName As Long, objType As Integer) As Long

Private Declare Function NWDSCreateContextHandle Lib "netwin32" _
(context As Long) As Long

Private Declare Function NWDSFreeContext Lib "netwin32" _
(ByVal context As Long) As Long

Private Declare Function NWDSMapIDToName Lib "netwin32" _
(ByVal context As Long, ByVal connHandle As Long, _
ByVal objectID As Long, ByVal namePtr As Long) As Long

Private Sub ByteArrayToString(dest As String, src() As Byte)
Dim i As Integer
i = 0
dest = ""
While src(i) <> 0
dest = dest + Chr(src(i))
i = i + 1
Wend
End Sub

Private Sub StringToByteArray(dest() As Byte, src As String)
Dim i As Integer
' Following For-Next loop should run to 0x0 char only
' but we do not care if it runs longer
For i = 0 To Len(src) - 1
dest(i) = CByte(Asc(Mid(src, i + 1, 1)))
Next i
End Sub

Private Function ConvertDOSTimeToString(dateTime As Long) As String
Dim day As Byte, month As Byte, year As Byte
Dim sec As Byte, min As Byte, hour As Byte

If dateTime = 0 Then
ConvertDOSTimeToString = &quot;?&quot;
Exit Function
End If

year = 0: month = 0: day = 0
If (dateTime And &HFFFF0000) <> 0 Then
year = CByte((dateTime And &HFE000000) \ 33554432) ' shifts right 25 times
month = CByte((dateTime And &H1E00000) \ 2097152)
day = CByte((dateTime And &H1F0000) \ 65536) ' shifts right 16 times
End If

hour = 0: min = 0: sec = 0
If (dateTime And &HFFFF) <> 0 Then
hour = CByte((dateTime And 63488) \ 2048) ' can't use hexa &HF800 - bug in VB !!??
min = CByte((dateTime And &H7E0) \ 32)
sec = CByte((dateTime And &H1F) * 2)
End If

ConvertDOSTimeToString = Str(month) & &quot;/&quot; & Str(day) & &quot;/&quot; & Str(year + 1980) _
& &quot;, &quot; & Str(hour) & &quot;:&quot; & Str(min) & &quot;:&quot; & Str(sec)

End Function

Private Function ConvertIDFromNDS(ID As Long, connHandle As Long) As String
Dim retCode As Long, context As Long
Dim byteName(255) As Byte

retCode = NWDSCreateContextHandle(context)
retCode = NWDSMapIDToName(context, connHandle, ID, VarPtr(byteName(0)))
If retCode = 0 Then
Call ByteArrayToString(ConvertIDFromNDS, byteName)
Else
ConvertIDFromNDS = &quot;?&quot;
End If
retCode = NWDSFreeContext(context)
End Function

Private Function ConvertIDFromBindery(ID As Long, connHandle As Long) As String
Dim retCode As Long
Dim objType As Integer
Dim byteName(63) As Byte

retCode = NWGetObjectName(connHandle, ID, VarPtr(byteName(0)), objType)
If retCode = 0 Then
Call ByteArrayToString(ConvertIDFromBindery, byteName)
Else
ConvertIDFromBindery = &quot;?&quot;
End If

End Function

Private Sub Command1_Click()
Dim retCode As Long, index As Long
Dim connHandle As Long, iterHandle As Long
Dim dirHandle As Byte
Dim fileName As String, anyString As String
Dim byteName(127) As Byte, rights As Byte
Dim fileInfo As NW_EXT_FILE_INFO
Dim i As Long
Dim version As VERSION_INFO

' 1. We have to open &quot;connection&quot; to the given server
' and to get valid connection handle
Call StringToByteArray(byteName, Text1.Text + Chr(0))
retCode = NWCCOpenConnByName(0, VarPtr(byteName(0)), NWCC_NAME_FORMAT_BIND, _
NWCC_OPEN_LICENSED, NWCC_TRAN_TYPE_WILD, connHandle)
If retCode <> 0 Then
MsgBox &quot;Cannot open connection to the given server (E=&quot; + Str(retCode) + &quot;)&quot;, vbCritical
Else

' 2. We need to translate given full path to upper chars first (DOS name space only !),
' then into byte array, and finally we need to extract file name
Call StringToByteArray(byteName, UCase(Text2.Text) + Chr(0))
For i = Len(Text2.Text) To 0 Step -1
If byteName(i) = AscB(&quot;\&quot;) Then
index = i
Exit For
End If
Next i
byteName(index) = 0
fileName = Mid(UCase(Text2.Text), index + 2)

' 3. Now we have in byteName variable full dir path and we can ask
' for temporary directory handle
retCode = NWAllocTemporaryDirectoryHandle(connHandle, 0, VarPtr(byteName(0)), dirHandle, rights)
If retCode <> 0 Then
MsgBox &quot;Cannot create directory handle (E=&quot; + Str(retCode) + &quot;)&quot;, vbCritical
Else
' 4. We can call NWIntScanExtendedInfo() now
' Although this function can be called in a loop and iterate
' we call it simply once because we specified full file name
' and in our DOS name space there is no chance for second entry

iterHandle = -1
retCode = NWIntScanExtendedInfo(connHandle, dirHandle, &H6, iterHandle, fileName + Chr(0), fileInfo, 0)

If retCode <> 0 Then
MsgBox &quot;NWIntScanExtendedInfo failed (E=&quot; + Str(retCode) + &quot;)&quot;, vbCritical
Else

' 5. Here we present results we received in NW_EXT_FILE_INFO structure

retCode = NWGetFileServerVersionInfo(connHandle, version)

Frame1.Caption = fileName
Text3.Text = ConvertDOSTimeToString(fileInfo.creationDateAndTime)

' 5.1. The way how to get ID from NW3.x servers (bindery) differs from
' the one for NW4.x/5.x (NDS) servers. SO we have to decide which version
' is installed on the server we communicate with
If version.fileServiceVersion > 3 Then
Text4.Text = ConvertIDFromNDS(fileInfo.ownerID, connHandle)
Else
Text4.Text = ConvertIDFromBindery(fileInfo.ownerID, connHandle)
End If

Text5.Text = ConvertDOSTimeToString(CLng(fileInfo.lastAccessDate * 65536))

Text6.Text = ConvertDOSTimeToString(fileInfo.lastArchiveDateAndTime)
If version.fileServiceVersion > 3 Then
Text7.Text = ConvertIDFromNDS(fileInfo.lastArchiverID, connHandle)
Else
Text7.Text = ConvertIDFromBindery(fileInfo.lastArchiverID, connHandle)
End If

Text8.Text = ConvertDOSTimeToString(fileInfo.updateDateAndTime)

If version.fileServiceVersion > 3 Then
Text9.Text = ConvertIDFromNDS(fileInfo.lastUpdatorID, connHandle)
Else
Text9.Text = ConvertIDFromBindery(fileInfo.lastUpdatorID, connHandle)
End If

' 5.2. Here we print out attributes:

' Clear all CheckBoxes

For i = 0 To Me.Controls.Count - 1
If TypeOf Me.Controls(i) Is CheckBox Then
Me.Controls(i).Value = 0
Me.Controls(i).Enabled = False
End If
Next
If fileInfo.attributes <> 0 Then
If fileInfo.attributes And &H1 Then
Check1.Enabled = True
Check1.Value = 2
End If
If fileInfo.attributes And &H2 Then
Check2.Enabled = True
Check2.Value = 2
End If
If fileInfo.attributes And &H4 Then
Check3.Enabled = True
Check3.Value = 2
End If
If fileInfo.attributes And &H8 Then
Check4.Enabled = True
Check4.Value = 2
End If
If fileInfo.attributes And &H10 Then
Check5.Enabled = True
Check5.Value = 2
End If
If fileInfo.attributes And &H20 Then
Check6.Enabled = True
Check6.Value = 2
End If
If fileInfo.attributes And &H80 Then
Check7.Enabled = True
Check7.Value = 2
End If
If fileInfo.attributes And &H1000 Then
Check8.Enabled = True
Check8.Value = 2
End If
If fileInfo.attributes And &H2000 Then
Check9.Enabled = True
Check9.Value = 2
End If
If fileInfo.attributes And &H4000 Then
Check10.Enabled = True
Check10.Value = 2
End If
If fileInfo.attributes And 32768 Then ' &H8000 does not work correctly in VB !
Check11.Enabled = True
Check11.Value = 2
End If
If fileInfo.attributes And &H10000 Then
Check12.Enabled = True
Check12.Value = 2
End If
If fileInfo.attributes And &H20000 Then
Check13.Enabled = True
Check13.Value = 2
End If
If fileInfo.attributes And &H40000 Then
Check14.Enabled = True
Check14.Value = 2
End If
If fileInfo.attributes And &H80000 Then
Check15.Enabled = True
Check15.Value = 2
End If
If fileInfo.attributes And &H400000 Then
Check16.Enabled = True
Check16.Value = 2
End If
If fileInfo.attributes And &H800000 Then
Check17.Enabled = True
Check17.Value = 2
End If
If fileInfo.attributes And &H2000000 Then
Check18.Enabled = True
Check18.Value = 2
End If
If fileInfo.attributes And &H4000000 Then
Check19.Enabled = True
Check19.Value = 2
End If
If fileInfo.attributes And &H8000000 Then
Check20.Enabled = True
Check20.Value = 2
End If
If fileInfo.attributes And &H20000000 Then
Check21.Enabled = True
Check21.Value = 2
End If
End If
End If

' 6. Finally some neded cleanup
retCode = NWDeallocateDirectoryHandle(connHandle, dirHandle)
End If
retCode = NWCCCloseConn(connHandle)
End If

End Sub

Private Sub Form_Load()
Dim retCode As Long
retCode = NWCallsInit(0, 0)
If retCode <> 0 Then
MsgBox &quot;NWCallsInit failed, E=&quot; + retCode, vbCritical
Unload Me
End If
End Sub
 
If you want the short filename, you can use:
Code:
Private Declare Function GetShortPathName Lib &quot;kernel32.dll&quot; Alias &quot;GetShortPathNameA&quot; (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Private Const MAX_PATH = 255

Private Function GetShortPath(ByVal Path As String) As String
    
    Dim lsPath As String
    Dim liLen As Long
    
    lsPath = Space$(MAX_PATH)
    liLen = GetShortPathName(Path, lsPath, Len(lsPath))
    GetShortPath = Left$(lsPath, liLen)
End Function

Remedy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top