GetLongPathName API

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
 
T

TerryFei

Hi,
Welcome to MSDN Newsgroup!

I can't repro this problem on my side. In the current scenario, I want to
confirm whether you can send me a complete sample to repro this question.
It will be better that the sample is written in C/C++. This will help us to
repro this issue and debug it on our side.

Thanks for your understanding!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top