Winevent setclipboard cf_hdrop TS


#1

I’m trying to allow copy and paste of stored documents to outlook etc

Using winevent I’ve used the example code for ds_setclipboard, which I’ve placed under a button in my program.

In my test environment nothing happens
In Production under TSPlus I get a SetClipboard Failed error.
The code is pretty much from the docs

Any clues anyone??

data

hDropStruct group
pFiles long ! offset from here to FileList
pt ulong ! drop point (in screen co-ords)
blank ulong
fNC long !Set for Non-Client area.
fWide long
FileList string(255) ! Null terminated list of null terminated file names.
end

code
hDropStruct.filelist = ‘C:\autoexec.bat<0,0>’ ! List of files. Note the double null terminator.
hDropStruct.pFiles = 20
hDropStruct.fWide = 0 ! ASCII
if ~ds_SetClipboard(CF_hDrop,hDropStruct) ! Place name in clipboard.
message(‘SetClipboardFailed’)
end


#2

Declaration of pt structure (pt ulong) is incorrect. Try this:
pt group
x long
y long
end


#3

since they are moth 32 bit I wouldn’t think there would be any difference. But I’ll try


#4

I hope, this link will help. https://docs.microsoft.com/en-us/windows/desktop/api/windows.foundation/ns-windows-foundation-point


#5

Correct link: https://docs.microsoft.com/en-us/previous-versions//dd162805(v=vs.85)


#6

I think “blank ulong” field was added to avoid to declare POINT group.


#7

pt ULONG ! 32 bits

pt GROUP ! 64 bits
X LONG ! 32 bits
Y LONG ! 32 bits
END


#8

Are you calling OpenClipboard ?


#9

also you need to pass memory handle to the SetClipboard call


#10

Hi Guys to be clear, it looks like this winevent call succeeds on my system but fails at the clients. The client is runnin Terminal services (TSPlus) on Win server 2008


#11

Update: I’m now not sure that winevent is doing the right thing. I’ve created a small test app (C10 src below) which appears to work on my system, excepting that I can’t paste anywhere.
Bruce has been emailed :slight_smile:

testFileCopy.zip (38.7 KB)


#12

According to your example… Why hDropStruct.pFiles = 20?
It must be SIZE(pt_x)+SIZE(pt_y)+SIZE(fNC)+SIZE(fWide), isn’t it? 4+4+1+1=10…


#13

BOOL is also a LONG 5 params at 4 bytes=20 which is where filename starts


#14

I think, MSDN in this case (https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/ns-shlobj_core-_dropfiles) assumes that BOOL EQUATE(BYTE).


#15

… and according to MSDN (“The offset of the file list from the beginning of this structure, in bytes.”): 4+4+4+1+1=14.


#16

DropFiles structure consists of 5 LONGs so 20 is correct. You need to allocate memory for this structure and file list which follows this structure and pass memory handle to SetClipBoardData call, VB code is below. It looks pretty much straight forward

Public Function ClipboardCopyFiles(Files() As String) As Boolean

Dim data As String
Dim df As DROPFILES
Dim hGlobal As Long
Dim lpGlobal As Long
Dim i As Long

’ Open and clear existing crud off clipboard.
If OpenClipboard(0&) Then
Call EmptyClipboard

’ Build double-null terminated list of files.
For i = LBound(Files) To UBound(Files)
data = data & Files(i) & vbNullChar
Next
data = data & vbNullChar

’ Allocate and get pointer to global memory,
’ then copy file list to it.
hGlobal = GlobalAlloc(GHND, Len(df) + Len(data))
If hGlobal Then
lpGlobal = GlobalLock(hGlobal)

’ Build DROPFILES structure in global memory.
df.pFiles = Len(df)
Call CopyMem(ByVal lpGlobal, df, Len(df))
Call CopyMem(ByVal (lpGlobal + Len(df)), ByVal data, Len(data))
Call GlobalUnlock(hGlobal)

’ Copy data to clipboard, and return success.
If SetClipboardData(CF_HDROP, hGlobal) Then
ClipboardCopyFiles = True
End If
End If

’ Clean up
Call CloseClipboard
End If


#17

Leonid, look at a first post. Seanh uses WinEvent, not Windows API…


#18

Update: I upgraded to winevent5 (I was on 3.99 Don’t know how I missed that upgrade).
That made things worse, winevent5 crashes explorer.
However it is now source, so I could find out what was happening, and more importantly fix it.

It now works. I can copy files and paste into an explorer window. Yeah!
The code has been sent to Capesoft.