Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Temperatura AC

Sunt sigure bolurle de plastic (B...

Dimensionare putere centrala / ca...

Impamantare suplimentara
 Scartiei frana fata bicicleta noua

Instalare aer conditionat in apar...

Telefoane prietenoase cu vederea?

Alegere teava pentru incalzire pr...
 Opinia publica despre medici/ asi...

Senzor Temp PMOD-TMP3 cu TCN75A

Amazing Race

Recomandare fosa ecologica
 La multi ani @LouisCyphre!

Vinieta Bulgaria Online

Investitie imobiliara in strainat...

Plita inducție gorenje IC340...
 

Clipboard files copy/paste, filenames longer than MAX_PATH

- - - - -
  • Please log in to reply
No replies to this topic

#1
addysoftware

addysoftware

    Ecological Member :)

  • Grup: Moderators
  • Posts: 7,553
  • Înscris: 12.04.2007
Salutare !

Lucrez la un program care face printre altele cam ce face si Windows Explorer, deocamdata (in viitor se vrea un fel de offline explorer, virtual raid sau cam asa ceva)
Am implementat zilele astea Clipboard-ul (files copy/paste) si merge, se pare, doar s-ar parea ca exista probleme de compatibilitate intre Explorer-ul Windows-ului (W10 x64) si fisierele al caror nume depaseste MAX_PATH (260 caractere). Cu alte cuvinte codul meu le baga in clipboard, am vazut ca le si scoate de acolo cu succes, dar Windows-ul nu vrea. Am chestia aia cu long filenames declarata deja in registrii, dar pe clipboard pare ca nu merge

Pun aici bucatile de cod, poate exista alte functii de scriere in Clipboard astfel incat Windowsul sa poata citi, doar ca nu le stiu eu; si cineva care le stie sa-mi dea si mie o indicatie.

Ar mai fi o chestie. La citire, am prealocat 4096 caractere ptr stringul receptor, in loc de MAX_PATH. E vreo problema? ca nu am testat de prea multe ori; ma tem sa nu iasa vreun crash de sistem, ceva, din cand in cand, cand nu te astepti.

Option Explicit
'md_ClipboardCopyPasteFiles002

'Memory alloc
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

Private Const GMEM_MOVEABLE = &H2
Private Const GMEM_ZEROINIT = &H40
Private Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)

Private Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Long

Private Const CF_HDROP = 15
Private Const CFSTR_PREFERREDDROPEFFECT As String = "Preferred DropEffect"

Private Type POINTAPI
x As Long
y As Long
End Type

Private Type DROPFILES
pFiles As Long
pt As POINTAPI
fNC As Long
fWide As Long
End Type
'______Public__________________
Public Enum FileDropEffectConstants
fdDropEffectNone = 0
fdDropEffectCopy = 1
fdDropEffectmove = 2
fdDropEffectLink = 4
End Enum


Public Function ClipboardSetFiles(Files() As String, Optional ByVal lEffect As Long) As Boolean
Dim i As Long

If OpenClipboard(0&) Then
	
	 Call EmptyClipboard
	
	 'Concatenate file paths with null terminators
	 Dim data As String
	 For i = LBound(Files) To UBound(Files)
			 data = data & Files(i) & vbNullChar
	 Next i
	 data = data & vbNullChar
	
	 'allocate mem for DropFiles struct
	 Dim dF As DROPFILES
	 Dim hMem1 As Long
	 Dim pMem1 As Long
	 hMem1 = GlobalAlloc(GHND, Len(dF) + Len(data))
	 If hMem1 Then
			 pMem1 = GlobalLock(hMem1)
			 dF.pFiles = Len(dF)
			 Call MoveMemory(ByVal pMem1, dF, Len(dF))
			 Call MoveMemory(ByVal (pMem1 + Len(dF)), ByVal data, Len(data))
			 Call GlobalUnlock(hMem1)
			 If SetClipboardData(CF_HDROP, hMem1) Then
				 ClipboardSetFiles = True
			 End If
	 End If
	
	 'alloc memory for the Effect
	 Dim hMem2 As Long
	 Dim pMem2 As Long
	 Dim lFormat As Long
	 Dim lReturn As Long
	 hMem2 = GlobalAlloc(GHND, Len(lEffect))
	 If hMem2 Then
			 pMem2 = GlobalLock(hMem2)
			 Call MoveMemory(ByVal pMem2, lEffect, Len(lEffect))
			 Call GlobalUnlock(hMem2)
			 lFormat = RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT)
			 lReturn = SetClipboardData(lFormat, hMem2)
	 End If
	
	 Call CloseClipboard

End If
End Function



Public Function ClipboardGetFiles(Files() As String, Optional ByRef DropEffect As FileDropEffectConstants) As Long
Dim hDrop As Long
Dim nFiles As Long
Dim k As Long
Dim fileName As String
'Const MAX_PATH As Long = 260
Dim lFormat As Long
Dim hMem As Long
Dim lEffect As Long

'interrogate clipboard
If IsClipboardFormatAvailable(CF_HDROP) Then
	 If OpenClipboard(0&) Then
			 hDrop = GetClipboardData(CF_HDROP)
			 If (hDrop) Then
					 nFiles = DragQueryFile(hDrop, -1&, "", 0)
					 'Debug.Print nFiles
					 ReDim Files(0 To nFiles - 1) As String
					 fileName = Space$(4096)
					 For k = 0 To nFiles - 1
							 Call DragQueryFile(hDrop, k, fileName, Len(fileName))
							 Files(k) = TrimNull(fileName)
							 'Debug.Print Files(k)
							 'Debug.Print Len(Files(k))
					 Next k
					 lFormat = RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT)
					 hMem = GetClipboardData(lFormat)
					 If (hMem) Then
							 MoveMemory lEffect, ByVal hMem, 4
							 DropEffect = lEffect
					 End If
			 End If
			 Call CloseClipboard
	 End If
	 ClipboardGetFiles = nFiles
End If
End Function



Edited by addysoftware, 12 May 2024 - 00:24.


Anunturi

Chirurgia cranio-cerebrală minim invazivă Chirurgia cranio-cerebrală minim invazivă

Tehnicile minim invazive impun utilizarea unei tehnologii ultramoderne.

Endoscoapele operatorii de diverse tipuri, microscopul operator dedicat, neuronavigația, neuroelectrofiziologia, tehnicile avansate de anestezie, chirurgia cu pacientul treaz reprezintă armamentarium fără de care neurochirurgia prin "gaura cheii" nu ar fi posibilă. Folosind tehnicile de mai sus, tratăm un spectru larg de patologii cranio-cerebrale.

www.neurohope.ro

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate