OK guys, simple Windows API stuff works. It doesn't cause MapInfo to crash,
or cause Windows to BSOD, because MapInfo necessarily creates a global copy
of the string when it passes it into SetClipboadData ByVal.
You can use separate compilation and a project file as below, or append
TestClipboardCopy.mb, CoypStringToClipboard.def, and
CopyStringToClipboard.mb into one file, rearranging the Include directives
appropriately.
---------------------------------------------------------------------
' TestClipboardCopy.mbp
[Link]
Application=TestClipboardCopy.mbx
Module=TestClipboardCopy.mbo
Module=CopyStringToClipboard.mb
---------------------------------------------------------------------
' TestClipboardCopy.mb
Include "CopyStringToClipboard.def"
declare sub main
sub main
if CopyStringToClipboard ("A string MapBasic placed on the ClipBoard!")
then note "copy succeeded"
else note "copy failed"
end if
end mapinfo
end sub
---------------------------------------------------------------------
' CopyStringToClipboard.def
declare function CopyStringToClipboard (ByVal s as string) as logical
---------------------------------------------------------------------
' CopyStringToClipboard.mb
include "MapBasic.def"
'
' Windows API stuff
'
define CF_TEXT 1
define BOOL smallint
declare function OpenClipboard lib "User32" (ByVal hwnd as integer) as BOOL
declare function CloseClipboard lib "User32" () as BOOL
declare function EmptyClipboard lib "User32" () as BOOL
declare function SetClipboardDataString
lib "User32" alias "SetClipboardData"
(byval fmt as smallint,
ByVal s as string) as integer
function CopyStringToClipboard (ByVal s as string) as logical
CopyStringToClipboard = FALSE
if (s <> "")
then if OpenClipboard(WindowInfo (WIN_MAPINFO, WIN_INFO_WND)) = 1
then if EmptyClipboard() = 1
then if SetClipboardDataString (CF_TEXT, s) <> 0
then CopyStringToClipboard = TRUE
end if
end if
if CloseClipboard() = 0
then note "Warning: failed to close clipboard."
end if
end if
end if
end function
________________________________
Spencer