By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

SHGetSpecialFolderLocation crashes

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JMW
Depending on what special folder you are looking for you can use this method...

Environment.GetFolderPath(System.Environment.Speci alFolder.MyComputer)

jason.
"Just Me" wrote:
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

Nov 20 '05 #2

P: n/a
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

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

" Just Me" <ne********@a-znet.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
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


Nov 20 '05 #3

P: n/a
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Oa**************@tk2msftngp13.phx.gbl...
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

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

" Just Me" <ne********@a-znet.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #4

P: n/a
That's the simplest solution if the System.Environment.SpecialFolder enum
matches CSIDL values. I'll check.

Thanks
"JMW" <JM*@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Depending on what special folder you are looking for you can use this method...
Environment.GetFolderPath(System.Environment.Speci alFolder.MyComputer)

jason.
"Just Me" wrote:
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

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.