G
Guest
This function refuses to return the long path name when called on Windows
2000 Professional. It does not return an error value or raise an exception,
it just does nothing.
<DllImport("kernel32")> _
Private Shared Function GetLongPathNameA(<MarshalAs(UnmanagedType.LPStr)>
ByVal ShortPath As String, <MarshalAs(UnmanagedType.LPStr)> ByVal LongPath As
String, ByVal BufferSize As Integer) As Integer
End Function
Private Function LongPathName(ByVal shortPathName As String) As String
Dim RV As Integer
Dim LongPath As String = ""
'Determine the size of the buffer needed.
RV = GetLongPathNameA(shortPathName, LongPath, LongPath.Length)
If (RV = 0) Then Return ""
'Allocate storage for the buffer and call again.
LongPath = Space(RV)
RV = GetLongPathNameA(shortPathName, LongPath, LongPath.Length)
If (RV = 0) Then Return ""
Return LongPath
End Function
When I call the function with shortPathName =
"C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp", the second call to GetLongPathNameA
returns the LongPath variable still filled with spaces and nothing happens.
This is not the case with the Unicode version of the function. I have left
out the try...catch block for simplicity.
Just a note. Some API functions let you call them with no buffer; however,
this one does not.
ie RV = GetShortPathNameW(longPathName, Nothing, 0)
2000 Professional. It does not return an error value or raise an exception,
it just does nothing.
<DllImport("kernel32")> _
Private Shared Function GetLongPathNameA(<MarshalAs(UnmanagedType.LPStr)>
ByVal ShortPath As String, <MarshalAs(UnmanagedType.LPStr)> ByVal LongPath As
String, ByVal BufferSize As Integer) As Integer
End Function
Private Function LongPathName(ByVal shortPathName As String) As String
Dim RV As Integer
Dim LongPath As String = ""
'Determine the size of the buffer needed.
RV = GetLongPathNameA(shortPathName, LongPath, LongPath.Length)
If (RV = 0) Then Return ""
'Allocate storage for the buffer and call again.
LongPath = Space(RV)
RV = GetLongPathNameA(shortPathName, LongPath, LongPath.Length)
If (RV = 0) Then Return ""
Return LongPath
End Function
When I call the function with shortPathName =
"C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp", the second call to GetLongPathNameA
returns the LongPath variable still filled with spaces and nothing happens.
This is not the case with the Unicode version of the function. I have left
out the try...catch block for simplicity.
Just a note. Some API functions let you call them with no buffer; however,
this one does not.
ie RV = GetShortPathNameW(longPathName, Nothing, 0)