Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to programmatically create a file link in the clipbo
Message
From
06/10/2006 03:01:37
 
 
To
05/10/2006 14:49:19
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01159071
Message ID:
01159956
Views:
24
>I tested it, and it worked great, thanks a lot! I added one small change, so that it can handle both one-dimensional and two-dimensional arrays, which I will need in my specific case. For other members who may need this functionality, here is the code
>FUNCTION CopyFiles2Clipboard(taFileList)
>  LOCAL lnDataLen, lcDropFiles, llOk, i, lhMem, lnPtr
>  #DEFINE CF_HDROP 15
>
>*  Global Memory Variables with Compile Time Constants
>  #DEFINE GMEM_MOVABLE    0x0002
>  #DEFINE GMEM_ZEROINIT   0x0040
>  #DEFINE GMEM_SHARE      0x2000
>*  Clipboard Functions
>  DECLARE LONG OpenClipboard IN user32 LONG HWND
>  DECLARE LONG CloseClipboard IN user32
>  DECLARE LONG EmptyClipboard IN user32
>  DECLARE LONG SetClipboardData In user32 LONG uFormat, LONG hMem
>
>*  Memory Management Functions
>  DECLARE LONG GlobalAlloc IN kernel32 LONG wFlags, LONG dwBytes
>  DECLARE LONG GlobalFree IN kernel32 LONG HMEM
>  DECLARE LONG GlobalLock IN kernel32 LONG HMEM
>  DECLARE LONG GlobalUnlock IN kernel32 LONG HMEM
>  DECLARE LONG RtlMoveMemory In kernel32 As CopyFromStr LONG lpDest, String @lpSrc, LONG iLen
>
>  llOk = .T.
>* Build DROPFILES structure
>  lcDropFiles = ;
>    CHR(20) + REPLICATE(CHR(0),3) + ;   && pFiles
>  REPLICATE(CHR(0),8) + ;             && pt
>  REPLICATE(CHR(0),8)                 && fNC + fWide
>* Add 0 deleimted file list
>
>  FOR i= 1 TO ALEN(taFileList,1)
>    If Alen(taFileList,2)=0 && onedimensional
>      lcDropFiles = lcDropFiles + taFileList[i] + CHR(0)
>    Else
>      lcDropFiles = lcDropFiles + taFileList[i,1] + CHR(0)
>    EndIf
>  ENDFOR
>* Final 0
>  lcDropFiles = lcDropFiles + CHR(0)
>  lnDataLen = LEN(lcDropFiles)
>* Copy DROPFILES into the allocated memory
>  lhMem = GlobalAlloc(GMEM_MOVABLE+GMEM_ZEROINIT+GMEM_SHARE,lnDataLen)
>  lnPtr = GlobalLock(lhMem)
>  CopyFromStr(lnPtr, @lcDropFiles, lnDataLen)
>  GlobalUnlock(lhMem)
>* Open clipboard and store DROPFILES into it
>  llOk = (OpenClipboard(0) <> 0)
>  IF llOk
>    EmptyClipboard()
>    llOk = (SetClipboardData(CF_HDROP, lhMem) <> 0)
>* If SetClipboardData is successful, the system will take ownership of the memory
>*   otherwise we have to free it
>    IF NOT llOk
>      GlobalFree(lhMem)
>    ENDIF
>* Close clipboard so other can access it
>    CloseClipboard()
>  ENDIF
>  RETURN llOk
>
Hi Tore,

PMFJI, I didn't follow the whole threads, but I think there is a leak problem in that code. Take out the GlobalFree() outside the IF llOK ... ENDIF. You should free the memory if Clipboard cannot be open or SetClipboardData is un-successful,

Regards
Herman
Previous
Reply
Map
View

Click here to load this message in the networking platform