How can I copy a textbuffer (eg. TextBuffer db 'hello world',0) to the clipboard?

I have tried all examples on the board, but I can't get them to work. I'm currently using a temporary solution by creating an off-screen edit box that I put the text in using SetDlgItemText and then copying the text by sending the WM_COPY message to it. This however feels very dirty and I really would like to know a proper way of doing it.

Posted on 2002-10-21 08:12:16 by Delight

invoke SetClipboardData,CF_TEXT,addr TextBuffer
Posted on 2002-10-21 09:03:45 by Const.Ex
I tried this

invoke CloseClipboard
invoke OpenClipboard,hWin
invoke EmptyClipboard
invoke SetClipboardData,CF_TEXT,offset Buffer
invoke CloseClipboard

But it crashed :(
Posted on 2002-10-21 09:07:39 by Delight
OpenClipboard at first
Posted on 2002-10-21 09:08:06 by Const.Ex
HGLOBAL clipbuffer;
char * buffer;
clipbuffer = GlobalAlloc(GMEM_DDESHARE, dource.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
Strcpy(buffer, LPCSTR(source));
invoke openClipBoard
.if eax!=0
invoke EmptyClipboard
invoke SetClipboardData,CF_TEXT,buffer
invoke CloseClipboard
I think it will work...
Let me try later.
Posted on 2002-10-21 09:18:11 by Const.Ex
I am knew such few of hMem.
Posted on 2002-10-21 09:23:59 by Const.Ex
i used this i found on the board in the app im working on
nLen dd ?
hMem dd ?
pMem dd ?

invoke lstrlen, addr yourtexthere
inc eax
mov nLen, eax
invoke OpenClipboard, 0
invoke GlobalAlloc, GHND, nLen
mov hMem, eax
invoke GlobalLock, eax
mov pMem, eax
lea esi,yourtexthere
mov edi, eax
mov ecx, nLen
rep movsb
invoke EmptyClipboard
invoke GlobalUnlock, hMem
invoke SetClipboardData, CF_TEXT, hMem
invoke CloseClipboard
Posted on 2002-10-21 18:56:00 by illwill
illwill, that code works perfectly. Thanks!
Posted on 2002-10-22 03:29:31 by Delight