Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to programmatically create a file link in the clipbo
Message
From
04/10/2006 16:56:56
 
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:
01159521
Views:
24
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?

For other users, 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) + CHR(0) + CHR(0) + CHR(0) + ;  && pFiles   
        REPLICATE(CHR(0),8) + ;         && pt   
        REPLICATE(CHR(0),8)             && fNC + fWide   
* Add 0 deleimted file list  
FOR i= 1 TO ALEN(taFileList,1)   
    lcDropFiles = lcDropFiles + taFileList[i,1] + CHR(0)   
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)   
    CloseClipboard()   
ENDIF  
GlobalFree(lhMem)   
RETURN llOk
>Hi Tore,
>
>Check http://sergey.berezniker.com/x/nAE
>
>>In an application we need to copy a link to a file into the clipboard, so that we can paste this link into Outlook and create an attachemnt. If this description of my need is unclear, I will describe the scenario.
>>
>>My user receives an email asking for more information about a given product. He wants to reply by making some small comments, and attaching a file, for instance a PDF or a DOC. Information about which file he shall attach, is in a memo field. So I want to add a button to his form which creates a link to this specific file, so that when he writes the reply in Outlook, he can simply press ctrl-v, and the file is attached.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform