<div>The other way is a bit more complicated.</div><div>Try this:</div><div><br></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>import std.stdio;</div><div>import core.stdc.string;</div>
<div>import std.string;</div><div><br></div><div>extern(Windows) {</div><div> bool OpenClipboard(void*);</div><div> void* GetClipboardData(uint);</div><div> void* SetClipboardData(uint, void*);</div><div> bool EmptyClipboard();</div>
<div> bool CloseClipboard();</div><div> void* GlobalAlloc(uint, size_t);</div><div> void* GlobalLock(void*);</div><div> bool GlobalUnlock(void*);</div><div>}</div><div><br></div><div>void main() {</div><div> if (OpenClipboard(null)) {</div>
<div> auto cstr = cast(char*)GetClipboardData( 1 );</div><div> if(cstr)</div><div> writeln(cstr[0..strlen(cstr)]);</div><div> EmptyClipboard();</div><div> </div><div> auto mystr = "my data";</div>
<div> void* handle = GlobalAlloc(2, mystr.length + 1);</div><div> void* ptr = GlobalLock(handle);</div><div> memcpy(ptr, toStringz(mystr), mystr.length + 1);</div><div> GlobalUnlock(handle);</div>
<div>
</div><div> SetClipboardData( 1, handle);</div><div> CloseClipboard();</div><div> }</div><div>}</div></div></blockquote><br><br><div class="gmail_quote">On Sun, Sep 11, 2011 at 10:50 PM, Joel Christensen <span dir="ltr"><<a href="mailto:joelcnz@gmail.com">joelcnz@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Thanks Jimmy. Your example worked. Or though I haven't managed to get the other way to work.<br>
<br>
[code]<div class="im"><br>
import std.stdio;<br>
//import core.stdc.string;<br></div>
import std.c.string;<br>
import std.string;<br>
import std.conv;<br>
<br>
extern(Windows) {<br>
bool OpenClipboard(void*);<br>
void* GetClipboardData(uint);<br>
void* SetClipboardData(uint, void*);<div class="im"><br>
}<br>
<br>
void main() {<br>
if (OpenClipboard(null)) {<br>
auto cstr = cast(char*)GetClipboardData( 1 );<br>
if (cstr)<br></div>
writeln(to!string(cast(char*)<u></u>cstr[0..strlen(cstr)]));<br>
<br>
SetClipboardData( 1, cast(char*)toStringz( "data set" ) );<br>
}<br>
}<br>
[/code]<br>
</blockquote></div><br>