-3
快速的问题:在这个例子代码:将变量内容复制到C中的剪贴板?
printf ("\nType in 1st address: ");
scanf ("%x", &address1);
address1 = (address1 - number1) * 2;
printf ("\nResult = %08X\n\n", address1);
我怎样才能VAR 地址1的内容复制到剪贴板?
快速的问题:在这个例子代码:将变量内容复制到C中的剪贴板?
printf ("\nType in 1st address: ");
scanf ("%x", &address1);
address1 = (address1 - number1) * 2;
printf ("\nResult = %08X\n\n", address1);
我怎样才能VAR 地址1的内容复制到剪贴板?
对于未来的读者,我决定展示如何在Windows中执行此操作的示例。
首先使用sprintf格式化数据(http://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm)如果格式不正确(const char *)。
然后使用下面的Windows API设置剪贴板数据。
这里是那些API的一个非常基本例如使用没有任何的回报/错误值检查。
const char *Str = "Hello world";
const size_t strLen = lstrlenA(Str) + 1;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, strLen); //Memory must be moveable!
memcpy(GlobalLock(hGlobal), Str, strLen);
GlobalUnlock(hGlobal);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_TEXT, hGlobal);
CloseClipboard();
这取决于你在哪个平台上运行。 – 2014-09-03 19:54:13
什么剪贴板? (C语言没有剪贴板) – stakx 2014-09-03 19:54:15
“address1”指向哪种数据?你想把什么样的数据放在剪贴板上? – 2014-09-03 19:55:33