
why isn't this api working?
Hello,
Quote:
> Private Declare Function PathCompactPath _
> Lib "shlwapi" Alias "PathCompactPathA" ( _
> ByVal hDC As IntPtr, _
> ByVal lpszPath As String, _
> ByVal dx As Integer) As Integer
> 'code
> Dim strFilePath As String = "C:\Program Files\Some
> Company\Some Product\File.txt"
> PathCompactPath(Me.Handle, strFilePath, 250)
> Dim strNewPath as String = strFilePath
> No matter what i change the size to (250), it only returns
> the file name ("...\File.txt").
You give PathCompactPath a Window Handle where a handle to a DC is expected.
This doesn't work.
Try the code below:
\\\
Private Declare Function GetWindowDC Lib "user32.dll" ( _
ByVal hwnd As IntPtr _
) As IntPtr
Private Declare Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal hdc As IntPtr _
) As IntPtr
Private Declare Function PathCompactPath Lib "shlwapi.dll" Alias
"PathCompactPathA" ( _
ByVal hDC As IntPtr, _
ByVal lpszPath As String, _
ByVal dx As Int32 _
) As Integer
Private Sub Test()
Dim hDC As IntPtr = GetWindowDC(Me.Handle)
Dim strFilePath As String = _
"C:\Program Files\Some Company\Some Product\bla\bla\File.txt"
PathCompactPath(hDC, strFilePath, 250)
MsgBox(strFilePath)
ReleaseDC(Me.Handle, hDC)
End Sub
///
Regards,
Herfried K. Wagner