ACE3/extensions/clipboard/ace_clipboard.cpp

106 lines
2.6 KiB
C++
Raw Normal View History

2015-05-02 21:18:42 +00:00
/*
* ace_clipboard.cpp
*
2016-02-17 23:07:06 +00:00
* Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit. Windows only.
2015-05-02 21:18:42 +00:00
*
* Takes:
* Localized string as string
*
* Returns:
* None
*/
2016-02-17 23:07:06 +00:00
#include "shared.hpp"
2016-02-17 23:07:06 +00:00
#include <stdlib.h>
2015-05-02 21:18:42 +00:00
#include <vector>
#include <string>
extern "C" {
EXPORT void __stdcall RVExtension(char *output, int outputSize, const char *function);
}
2015-05-02 21:18:42 +00:00
2015-05-02 22:28:40 +00:00
std::string gClipboardData;
2015-05-02 21:18:42 +00:00
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
2015-05-02 22:28:40 +00:00
std::string cur_input(function);
2015-05-02 21:18:42 +00:00
std::string result;
ZERO_OUTPUT();
if (cur_input.length() < 1) {
EXTENSION_RETURN();
}
2015-05-02 21:18:42 +00:00
2015-05-02 22:28:40 +00:00
if (!strcmp(function, "version")) {
2016-02-17 23:07:06 +00:00
strncpy_s(output, outputSize, ACE_FULL_VERSION_STR, _TRUNCATE);
EXTENSION_RETURN();
2015-05-02 21:18:42 +00:00
}
2016-02-17 23:07:06 +00:00
#ifndef _WIN32
EXTENSION_RETURN();
#endif
2015-05-02 21:18:42 +00:00
2016-02-17 23:07:06 +00:00
if (!strcmp(function, "--COMPLETE--"))
{
2015-05-02 22:28:40 +00:00
HGLOBAL hClipboardData = GlobalAlloc(GMEM_FIXED, gClipboardData.length() + 1);
2016-02-17 23:07:06 +00:00
if (!hClipboardData)
{
2015-05-02 22:28:40 +00:00
result = "GlobalAlloc() failed, GetLastError=" + GetLastError();
gClipboardData = "";
EXTENSION_RETURN();
2015-05-02 22:28:40 +00:00
}
char *pClipboardData = (char *)GlobalLock(hClipboardData);
2016-02-17 23:07:06 +00:00
if (!pClipboardData)
{
2015-05-02 22:28:40 +00:00
result = "GlobalLock() failed, GetLastError=" + GetLastError();
gClipboardData = "";
EXTENSION_RETURN();
2015-05-02 22:28:40 +00:00
}
2016-02-17 23:07:06 +00:00
strncpy_s(pClipboardData, gClipboardData.length(), gClipboardData.c_str(), _TRUNCATE);
2015-05-02 22:28:40 +00:00
GlobalUnlock(hClipboardData);
2016-02-17 23:07:06 +00:00
if (!OpenClipboard(NULL))
{
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
2015-05-02 22:28:40 +00:00
}
2016-02-17 23:07:06 +00:00
else
{
if (!EmptyClipboard())
{
2015-05-02 22:28:40 +00:00
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
}
2016-02-17 23:07:06 +00:00
else
{
if (!SetClipboardData(CF_TEXT, hClipboardData))
{
2015-05-02 22:28:40 +00:00
result = "SetClipboardData() failed, GetLastError=" + GetLastError();
}
2016-02-17 23:07:06 +00:00
else
{
if (!CloseClipboard())
{
2015-05-02 22:28:40 +00:00
result = "CloseClipboard() failed, GetLastError=" + GetLastError();
}
2015-05-02 21:18:42 +00:00
}
}
}
2015-05-02 22:28:40 +00:00
gClipboardData = "";
2016-02-17 23:07:06 +00:00
}
else
{
2015-05-02 22:28:40 +00:00
gClipboardData = gClipboardData + cur_input;
2015-05-02 21:18:42 +00:00
}
2016-02-17 23:07:06 +00:00
if (result.length() > 1)
{
strncpy_s(output, outputSize, result.c_str(), _TRUNCATE);
}
2015-05-02 21:18:42 +00:00
EXTENSION_RETURN();
2015-05-02 21:18:42 +00:00
}