Strings and API calls

BlitzMax Forums/BlitzMax Programming/Strings and API calls

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

I need to pass a string to the Win32 API function 'SetClipboardData' but I'm not having much luck ...

What I'm attempting to do is place a string of characters into the clipboard. I've tried various methods but the string does not arrive there.

SetClipboardData wants an INT which is a handle to the string of text. In the example here I'm converting the text to a sequence of bytes and passing the results as an INT.
No luck though. Any ideas how you do this?

' clipboard paste text example

Extern "Win32"
 Function OpenClipboard%(hwnd%)
 Function CloseClipboard%()
 Function EmptyClipboard%()
 Function SetClipboardData%(format%,hMem%)
End Extern 

' -----------------------------------------------

Global txt$="Hello from BlitzMax!"

Const CF_TEXT=1

If OpenClipboard(0)
	EmptyClipboard
	SetClipboardData CF_TEXT, Int(txt.ToCString())
	CloseClipboard
	FlushMem
Else
	RuntimeError "Failed to open Clipboard"
EndIf

End