470,862 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

GetLongPathName API

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

Mar 31 '06 #1
1 2882
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.)

--------------------
Thread-Topic: GetLongPathName API
thread-index: AcZU6ZL2qqqEK9xMSomuvmh/+g5M8g==
X-WBNR-Posting-Host: 140.90.54.57
From: =?Utf-8?B?c2F0ZWxpdGU=?= <sa******@newsgroups.nospam>
Subject: GetLongPathName API
Date: Fri, 31 Mar 2006 09:35:59 -0800
Lines: 52
Message-ID: <72**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
Newsgroups: microsoft.public.dotnet.general
Path: TK2MSFTNGXA01.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.general:192230
NNTP-Posting-Host: TK2MSFTNGXA01.phx.gbl 10.40.2.250
X-Tomcat-NG: microsoft.public.dotnet.general

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 froma 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 scratchworkspaces 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 thedialog 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 inorder to "reset" the GetLongPathName function.

Something else I have noticed is that I call the same function from anotherpat 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, ByVallongPathBufferSize 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


Apr 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ken Dyck | last post: by
6 posts views Thread by Charles Conlow | last post: by
2 posts views Thread by Matt Theule | last post: by
4 posts views Thread by Henry | last post: by
1 post views Thread by Jim Tittsler | last post: by
reply views Thread by mjheitland | last post: by
16 posts views Thread by Stef Mientki | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.