D
**Developer**
Been reading some of the Marshal doc and am a little confused.
Anyway, I've been using the following and it works OK.
Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (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
Tried this because I saw some place (not in the doc) that
UnmanagedType.LPTStr was the default for String. This works too.
Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (ByVal hWnd
As Integer, _
ByVal nFolder As Integer, ByVal nToken As Integer, _
ByVal dwFlags As Integer, _
ByVal lpszPath As String) As Boolean
Is that correct. I.e., in VB, String mashal defaults to
UnmanagedType.LPTStr so UnmanagedType.LPTStr need not be included??
This is how it's used:
Dim lPath As String = Space(260)
If Library.Shell.SHGetFolderPath(0, k, 0, 0, lPath) = 0 Then
lPath = lPath.Trim
lPath = lPath.Substring(0, lPath.Length - 1)
GetSpecialPath = lPath
End If
Finally, is that the correct way to do it or should I use StringBuilder.
If it's not the correct way, why not? It appears to work OK.
Thanks in advance
Anyway, I've been using the following and it works OK.
Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (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
Tried this because I saw some place (not in the doc) that
UnmanagedType.LPTStr was the default for String. This works too.
Public Declare Auto Function SHGetFolderPath Lib "shell32.dll" (ByVal hWnd
As Integer, _
ByVal nFolder As Integer, ByVal nToken As Integer, _
ByVal dwFlags As Integer, _
ByVal lpszPath As String) As Boolean
Is that correct. I.e., in VB, String mashal defaults to
UnmanagedType.LPTStr so UnmanagedType.LPTStr need not be included??
This is how it's used:
Dim lPath As String = Space(260)
If Library.Shell.SHGetFolderPath(0, k, 0, 0, lPath) = 0 Then
lPath = lPath.Trim
lPath = lPath.Substring(0, lPath.Length - 1)
GetSpecialPath = lPath
End If
Finally, is that the correct way to do it or should I use StringBuilder.
If it's not the correct way, why not? It appears to work OK.
Thanks in advance