|
Copy Dream URL To ClipBoard |
|
Written by Dream Dancer
|
|
Aug 16, 2010 at 12:48 PM |
' wrapper to handle copying a dreamurl to clipboard using API
SUB CopyDreamToClipboard(dIndex AS LONG)
LOCAL DreamUrl AS STRING
LOCAL UrlSize AS LONG
LOCAL ClipName AS ASCIIZ PTR
LOCAL hMemory AS DWORD
LOCAL pMemory AS DWORD
LOCAL bClip AS LONG
DreamUrl = Dreams.DreamName(dIndex)
' oversize the buffer just because it's safer that way
UrlSize = (((LEN(DreamUrl) + 1) / 4) + 1) * 4
hMemory = GlobalAlloc(%GHND OR %GMEM_SHARE, UrlSize)
IF (hMemory = 0) THEN
' bail, failed to get a global memory object
EXIT SUB
END IF
pMemory = GlobalLock(hMemory)
IF (pMemory = 0) THEN
' bail, failed to lock the memory, free block
GlobalFree hMemory
EXIT SUB
END IF
' have block, address it as though it was ascii ClipName = pMemory ' take advantage of PB's pointer usage over CopyMemory API @ClipName = DreamUrl ' we assume below works due to getting this far
GlobalUnlock hMemory
' attempt to acquire clipboard and set the block
bClip = OpenClipboard(hWinMain)
IF (ISFALSE bClip) THEN
' bail, could not get ownership of clipboard, free block
GlobalFree hMemory
EXIT SUB
END IF
EmptyClipboard
bClip = SetClipboardData(%CF_TEXT, hMemory)
IF (ISFALSE bClip) THEN
' bail? failed to set clipboard data? free block
GlobalFree hMemory
END IF
' close clipboard in either case
CloseClipboard
END SUB
GeSHi parsed in 0.151160955429 seconds.
|
|
Last Updated ( Aug 16, 2010 at 12:51 PM )
|