Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to programmatically create a file link in the clipbo
Message
From
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:
01159816
Views:
21
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
>Tore,
>
>I found the problem and fixed it. Try updated code and let me now.
>
>>I finally got the chance to try your code, and after adding ",1" to the for-next loop, it works great, except for one thing. Every second time I run the code, I get an error when I ctrl-v into Outlook, "Cannot create attachment. Out of memory or system reesources.....". If I run it twice or four times, I get no error, but if I run it once or three times, I get the error. Clearly there must be some cleanup missing. Can you spot it?
>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform