SHGetSpecialFolderLocation crashes

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

I tried the "A" version and Auto

They all crash




Anyone have a suggestion as to what else I could try??



Public Declare Function SHGetPathFromIDList Lib "shell32" Alias
"SHGetPathFromIDListW" (ByVal Pidl As Integer, _
<MarshalAs(UnmanagedType.LPStr, SizeConst:=MAX_PATH)> ByRef pszPath As
StringBuilder) As Integer



Private Function GetSpecialPath(ByVal k As ShellSpecialFolderConstants)

...snip

Dim sb As New StringBuilder(MAX_PATH)

sb.Append(Space(MAX_PATH))

Try

PidlFound = SHGetSpecialFolderLocation(0, k, lngPidl)

If PidlFound = 0 Then

Try

FolderFound = SHGetPathFromIDList(lngPidl, sb) CRASHES HERE WITH UNHANDLED
EXCEPTION

Catch ex As Exception
 
Depending on what special folder you are looking for you can use this method...

Environment.GetFolderPath(System.Environment.SpecialFolder.MyComputer)

jason.
 
Hi,

What path are you trying to get? This works.

<DllImport("shell32.dll", entrypoint:="SHGetFolderPathW", _

CallingConvention:=CallingConvention.StdCall)> _

Private Shared Function SHGetFolderPath(ByVal hWnd As Integer, _

ByVal nFolder As Integer, ByVal nToken As Integer, _

ByVal dwFlags As Integer, _

<MarshalAs(UnmanagedType.LPTStr)> ByVal lpszPath As String) As Boolean

End Function



Dim strPath As String = Space(260)

If SHGetFolderPath(0, CSIDL_CDBURN_AREA, 0, 0, strPath) = 0 Then

strPath = strPath.Trim

strPath = strPath.Substring(0, strPath.Length - 1)

mstrBurnPath = strPath + "\"

End If



Ken

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

I tried the "A" version and Auto

They all crash




Anyone have a suggestion as to what else I could try??



Public Declare Function SHGetPathFromIDList Lib "shell32" Alias
"SHGetPathFromIDListW" (ByVal Pidl As Integer, _
<MarshalAs(UnmanagedType.LPStr, SizeConst:=MAX_PATH)> ByRef pszPath As
StringBuilder) As Integer



Private Function GetSpecialPath(ByVal k As ShellSpecialFolderConstants)

...snip

Dim sb As New StringBuilder(MAX_PATH)

sb.Append(Space(MAX_PATH))

Try

PidlFound = SHGetSpecialFolderLocation(0, k, lngPidl)

If PidlFound = 0 Then

Try

FolderFound = SHGetPathFromIDList(lngPidl, sb) CRASHES HERE WITH UNHANDLED
EXCEPTION

Catch ex As Exception
 
Thanks, it does work.

1) I'd appreciate it if you'd tell me why String works in this case.
Since String can't be changed I thought you'd use StringBuilder since you're
looking for a return in that variable.
I believe that's what the Doc says to do.

2)How come the String is passed ByVal?
I thought that meant to make a copy and pass a reference to that copy so
your variable would never get changed!

3)Instead of using the "W" version would it still work if you used the "A"
version?

Thanks again
 
That's the simplest solution if the System.Environment.SpecialFolder enum
matches CSIDL values. I'll check.

Thanks
 

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

Back
Top