My logic

  • Thread starter Thread starter Innovators World Wide
  • Start date Start date
I

Innovators World Wide

Guest
Something is wrong with my Logic.

What I am doing.

I am trying to get the target paths of all files dragged to form. Regardless of uwp / .lnk I need uwp to return the auimd
so I can launch it with appxlauncher.

I am simply (for testing) using a listbox with DragOver and DragDrop

My Source for testing

Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Text

Public ShellIdListArrayName As String = "Shell IDList Array"
Public Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidl As IntPtr, ByVal pszPath As StringBuilder) As Integer
Public Declare Function ILCombine Lib "shell32.dll" (ByVal pidl1 As IntPtr, ByVal pidl2 As IntPtr) As IntPtr
Public Declare Sub ILFree Lib "shell32.dll" (ByVal pidl As IntPtr)

Private Sub ListBox1_DragEnter(sender As Object, e As DragEventArgs) Handles ListBox1.DragEnter
If e.Data.GetDataPresent(ShellIdListArrayName) Then
e.Effect = DragDropEffects.Link
'ElseIf e.Data.GetDataPresent() Then

End If
End Sub

Private Sub ListBox1_DragDrop(sender As Object, e As DragEventArgs) Handles ListBox1.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path1 In files
ListBox1.Items.Add(path1)
Next



Dim ms = CType(e.Data.GetData(ShellIdListArrayName), MemoryStream)
Dim bytes() As Byte = ms.ToArray
Dim p As IntPtr = Marshal.AllocHGlobal(bytes.Length)
Marshal.Copy(bytes, 0, p, bytes.Length)
Dim cidl As UInteger = CType(Marshal.ReadInt32(p, 0), UInteger)
Dim offset As Integer
Dim parentpidl As IntPtr = CType((CType(p, Integer) + CType(Marshal.ReadInt32(p, offset), UInteger)), IntPtr)
Dim path As StringBuilder = New StringBuilder(256)
SHGetPathFromIDList(parentpidl, path)
Dim i As Integer = 1
Do While (i <= cidl)
Dim relpidl As IntPtr = CType((CType(p, Integer) + CType(Marshal.ReadInt32(p, offset), UInteger)), IntPtr)
Dim abspidl As IntPtr = ILCombine(parentpidl, relpidl)
If (SHGetPathFromIDList(abspidl, path) <> 0) Then
'yield
ListBox1.Items.Add(path.ToString)
End If

ILFree(abspidl)
i = (i + 1)
Loop


End Sub
The first part of this works for .lnk it returns the target path. The purpose of the second part was an attempt to get


Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
from dragging (let's say) Calculator (or any uwp) from start menu


Dim ms = CType(e.Data.GetData(ShellIdListArrayName), MemoryStream)
Dim bytes() As Byte = ms.ToArray
Dim p As IntPtr = Marshal.AllocHGlobal(bytes.Length)
Marshal.Copy(bytes, 0, p, bytes.Length)
Dim cidl As UInteger = CType(Marshal.ReadInt32(p, 0), UInteger)
Dim offset As Integer
Dim parentpidl As IntPtr = CType((CType(p, Integer) + CType(Marshal.ReadInt32(p, offset), UInteger)), IntPtr)
Dim path As StringBuilder = New StringBuilder(256)
SHGetPathFromIDList(parentpidl, path)
Dim i As Integer = 1
Do While (i <= cidl)
Dim relpidl As IntPtr = CType((CType(p, Integer) + CType(Marshal.ReadInt32(p, offset), UInteger)), IntPtr)
Dim abspidl As IntPtr = ILCombine(parentpidl, relpidl)
If (SHGetPathFromIDList(abspidl, path) <> 0) Then
'yield
ListBox1.Items.Add(path.ToString)
End If

ILFree(abspidl)
i = (i + 1)
Loop

clearly this is wrong and my thought process / logic is wrong.

It only returns C:/user/username/Desktop regardless of what is dropped.

Can anyone think of a way to get the AUIMD or "Target" of a uwp being dragged onto a Windows Form ?

I would try using


CFSTR_SHELLIDLIST


But I am not sure how I would implement Clipboard formats to get the AUIMD. Which is why I was trying the above idea seeing as it returns the Shell ID Array in the same way I (thought,assume) CFSTR_SHELLIDLIST would

Continue reading...
 
Back
Top