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.

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


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
Sorry....
OpenClipboard at first
Posted on 2002-10-21 09:08:06 by Const.Ex
VC's CODE:
if(openClipboard())
{
HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, dource.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
Strcpy(buffer, LPCSTR(source));
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
===========================
invoke openClipBoard
.if eax!=0
invoke EmptyClipboard
invoke SetClipboardData,CF_TEXT,buffer
invoke CloseClipboard
.endif
I think it will work...
Let me try later.
Posted on 2002-10-21 09:18:11 by Const.Ex
http://www.codeguru.com/clipboard/text_tofrom_clipboard.shtml
sorry.
I am knew such few of hMem.
:stupid:
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
.data?
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