Skip to content

Instantly share code, notes, and snippets.

@ysc3839 ysc3839/CF_HDROP.py
Created Dec 21, 2017

Embed
What would you like to do?
from ctypes import windll, create_unicode_buffer, c_void_p, c_uint, c_wchar_p
kernel32 = windll.kernel32
GlobalLock = kernel32.GlobalLock
GlobalLock.argtypes = [c_void_p]
GlobalLock.restype = c_void_p
GlobalUnlock = kernel32.GlobalUnlock
GlobalUnlock.argtypes = [c_void_p]
user32 = windll.user32
GetClipboardData = user32.GetClipboardData
GetClipboardData.restype = c_void_p
DragQueryFile = windll.shell32.DragQueryFileW
DragQueryFile.argtypes = [c_void_p, c_uint, c_wchar_p, c_uint]
CF_HDROP = 15
def get_clipboard_files():
file_list = []
if user32.OpenClipboard(None):
hGlobal = user32.GetClipboardData(CF_HDROP)
if hGlobal:
hDrop = GlobalLock(hGlobal)
if hDrop:
count = DragQueryFile(hDrop, 0xFFFFFFFF, None, 0)
for i in range(count):
length = DragQueryFile(hDrop, i, None, 0)
buffer = create_unicode_buffer(length)
DragQueryFile(hDrop, i, buffer, length + 1)
file_list.append(buffer.value)
GlobalUnlock(hGlobal)
user32.CloseClipboard()
return file_list
if __name__ == '__main__':
print(get_clipboard_files())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.