Either I am doing some thing wrong or there is a problem with the subroutine CopyStringToClipboard:
SUB CopyStringToClipboard(INT hwnd, string text)
UINT handle = GlobalAlloc(GHND, LEN(text) + 1)
POINTER lock = GlobalLock(handle)
memcpy(lock, text, LEN(text) + 1)
GlobalFree(handle) 'note: this line is not present in any example at all but I'm pretty sure that its absence will produce a memory leak :/
I am sending it the dialog d1.hwnd and an ISTRING  value. It does copy to the clipboard some times and some times it does not. Just wondering if any one else has had the problem. In the program I am using it in, I have it copy once, then do a little more stuff and then try to copy again. It is the second copy that does not work.
Remove this line.....
GlobalFree(handle) - that's the problem, remove it and everything should be fine.
I did some digging and Andy's right... if the call to SetClipboardData succeeds the system calls GlobalFree(handle) for you, but you MUST pass a valid window handle (hwnd).
If you are still having problems, try the opposite, call CopyStringToClipboard with a null handle (hwnd = 0) and replace GHND by GMEM_MOVEABLE.
CF_TEXT should work for strings only. If you are using wstring stuff change it to CF_UNICODETEXT.
Andy's suggestion worked and the program works as I want it to.
Thanks to both Andy and fasecero. I will also keep the info on the WSTRING, even though I have not yet found a need for it.
Quote from: billhslnI will also keep the info on the WSTRING, even though I have not yet found a need for it.
If such case takes place the allocated memory size would need to be updated to
2 * LEN(text) + 2