G
Guest
I am having some strange problems with using the GetLongPathName API in a
..Net app that I am writing. Simply put, the app runs a process (invoked from
a dialog) that writes out temporary files to a scratch workspace. For
reasons that would take to long to explain, I am given a path to the scratch
workspaces in Short format. I am using GetLongPathName to, well get the
long path name.
So when the process runs, it writes out status messages to a textbox on the
dialog and scratch files to the temp workspace. Everything works as it
should on the first run of the process. However, on subsequent runs the
GetLongPathName is failing. It either returns nothing or strangely enough,
it returns the text that was written to the dialog textbox. Closing the
dialog and reopening does not help and I have to completely exit the app in
order to "reset" the GetLongPathName function.
Something else I have noticed is that I call the same function from another
pat of my app and its works great... never fails. This call is not being
made from a dialog so I suspect that has something to do with this.
Does anyone out there have any explanation as to what might be wrong here?
Here is the code I am using to wrap the API
Module MiscTools
Private Const bufferSize As Integer = 256
Public Class LongPathWrap
Declare Auto Function GetLongPathName Lib "kernel32.dll" (ByVal
shortPath As String, ByVal longPathBuffer As System.Text.StringBuilder, ByVal
longPathBufferSize As Integer) As Integer
End Class
Public Function GetLongPathName(ByVal shortPathName As String) As String
Dim buffer As New System.Text.StringBuilder(255)
Dim GLP As New LongPathWrap
Try
If shortPathName Is Nothing Then Return Nothing
Dim int As Integer
int = GLP.GetLongPathName(shortPathName, buffer, 255)
Return buffer.ToString
Catch ex As Exception
Return Nothing
Finally
buffer = Nothing
GLP = Nothing
End Try
End Function
End Module
..Net app that I am writing. Simply put, the app runs a process (invoked from
a dialog) that writes out temporary files to a scratch workspace. For
reasons that would take to long to explain, I am given a path to the scratch
workspaces in Short format. I am using GetLongPathName to, well get the
long path name.
So when the process runs, it writes out status messages to a textbox on the
dialog and scratch files to the temp workspace. Everything works as it
should on the first run of the process. However, on subsequent runs the
GetLongPathName is failing. It either returns nothing or strangely enough,
it returns the text that was written to the dialog textbox. Closing the
dialog and reopening does not help and I have to completely exit the app in
order to "reset" the GetLongPathName function.
Something else I have noticed is that I call the same function from another
pat of my app and its works great... never fails. This call is not being
made from a dialog so I suspect that has something to do with this.
Does anyone out there have any explanation as to what might be wrong here?
Here is the code I am using to wrap the API
Module MiscTools
Private Const bufferSize As Integer = 256
Public Class LongPathWrap
Declare Auto Function GetLongPathName Lib "kernel32.dll" (ByVal
shortPath As String, ByVal longPathBuffer As System.Text.StringBuilder, ByVal
longPathBufferSize As Integer) As Integer
End Class
Public Function GetLongPathName(ByVal shortPathName As String) As String
Dim buffer As New System.Text.StringBuilder(255)
Dim GLP As New LongPathWrap
Try
If shortPathName Is Nothing Then Return Nothing
Dim int As Integer
int = GLP.GetLongPathName(shortPathName, buffer, 255)
Return buffer.ToString
Catch ex As Exception
Return Nothing
Finally
buffer = Nothing
GLP = Nothing
End Try
End Function
End Module