I am trying to copy files into the clipboard so they can be pasted to windows explorer or as an attachment into outlook from my application. I found the below referenced method for doing this. the code compiles and run with no error, but nothing is placed into the clipboard. My assumption is there is a problem with the format of the file string I am sending to the function (yellow highlight). This function should allow for multiple files to be selected and placed into the clipboard, but I am just testing with a single file. Also wondering if the Green Highlight - Preferred drop effect should be a value not a text string. The MS documentation on this argument was not easy to understand how to format this item.
This code was also very old. Not sure if something has changed with newer Windows OS.
Any help is greatly appreciated.
Rick
boolean lb_return
ulong hdf,h2
ulong df,D2
ulong drop[]
ulong closing
blob{1000} buf1
blob{4} buf2
long ll_pos, ll_len
string files
string CFSTR_PREFERREDDROPEFFECT = 'Preferred DropEffect';
ulong DROPEFFECT_COPY = 1;
uint copyformat
ll_len = len(files) + 1
drop = {ll_len,0,0,0,0 }
closing = 0
format = 15
ll_pos = blobedit(buf1,1,drop[1])
ll_pos = blobedit(buf1,5,drop[2])
ll_pos = blobedit(buf1,9,drop[3])
ll_pos = blobedit(buf1,13,drop[4])
ll_pos = blobedit(buf1,17,drop[5])
ll_pos = blobedit(buf1,ll_pos,closing)
//hdf = GlobalAlloc(66, ll_pos)
df = GlobalLock(hdf);
CopyMemory(df, buf1 , ll_pos)
GlobalUnlock(hdf)
h2 = GlobalAlloc(66,4)
d2 = GlobalLock(h2);
CopyMemory(d2, buf2 , 4)
GlobalUnlock(h2)
if lb_return then
lb_return = EmptyClipboard();
messagebox("test",lb_return);
copyformat = RegisterClipboardFormatA (CFSTR_PREFERREDDROPEFFECT);
messagebox("test",copyformat);
SetClipboardData(copyformat,d2);
SetClipboardData(format,df);
lb_return = CloseClipboard();
else
messagebox("test","Copy to clipboard failed!!!");
end if
if lb_return then
return 1
else
return -1
end if
Can you supply the URL to the web page you found that contains the original code?
You might also search for example code in C++ or C# that does what you are wanting to accomplish. If you can find a working code sample, it may be easier to port that code to PowerScript.
http://codeverge.com/sybase.powerbuilder.general/copy-file-to-clipboard/944553
I have done a lot of trial and error and I think the issue has to do with null characters needed at the end of the "file path" for the setclipboarddata cf_hdrop.
The MS documentation says the CF_HDrop format for the filename array should be
c:\temp1.txt'\0'c:\temp2.txt'\0''\0' Where '\0' is a null value. So one null after each file path and two nulls at the end. I don't think that is getting pushed into the blob with this code. I have tried many different methods of putting nulls in there and no luck. If I make a null character and put it on the end, it crashes on the copymemory call. Other methods cause explorer.exe to crash and restart, but no error or file paste.
Might need to not use this old code and look for the port you suggested. I have found several examples, but am struggling to convert to powerscript.
https://stackoverflow.com/questions/45347710/getclipboarddatacf-hdrop-fails-in-cut-and-paste
https://www.codeguru.com/cpp/w-p/clipboard/article.php/c2997/Copying-Files-into-Explorer.htm
Thanks for taking a look.
Rick