2015-05-02 21:18:42 +00:00
|
|
|
/*
|
|
|
|
* ace_clipboard.cpp
|
|
|
|
*
|
|
|
|
* Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit.
|
|
|
|
*
|
|
|
|
* Takes:
|
|
|
|
* Localized string as string
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* None
|
|
|
|
*/
|
2015-05-13 15:34:14 +00:00
|
|
|
#include "shared.hpp"
|
2015-05-02 21:18:42 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
extern "C" {
|
2015-05-17 17:10:02 +00:00
|
|
|
EXPORT void __stdcall RVExtension(char *output, int outputSize, const char *function);
|
2015-09-08 19:53:29 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2015-05-13 15:34:14 +00:00
|
|
|
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")) {
|
|
|
|
strncpy(output, ACE_FULL_VERSION_STR, outputSize);
|
2015-05-13 15:34:14 +00:00
|
|
|
EXTENSION_RETURN();
|
2015-05-02 21:18:42 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 22:28:40 +00:00
|
|
|
#ifdef _WIN32
|
2015-05-02 21:18:42 +00:00
|
|
|
|
2015-05-02 22:28:40 +00:00
|
|
|
if (!strcmp(function, "--COMPLETE--")) {
|
|
|
|
HGLOBAL hClipboardData = GlobalAlloc(GMEM_FIXED, gClipboardData.length() + 1);
|
|
|
|
if (!hClipboardData) {
|
|
|
|
result = "GlobalAlloc() failed, GetLastError=" + GetLastError();
|
|
|
|
gClipboardData = "";
|
2015-05-13 15:34:14 +00:00
|
|
|
EXTENSION_RETURN();
|
2015-05-02 22:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *pClipboardData = (char *)GlobalLock(hClipboardData);
|
|
|
|
if (!pClipboardData) {
|
|
|
|
result = "GlobalLock() failed, GetLastError=" + GetLastError();
|
|
|
|
gClipboardData = "";
|
2015-05-13 15:34:14 +00:00
|
|
|
EXTENSION_RETURN();
|
2015-05-02 22:28:40 +00:00
|
|
|
}
|
|
|
|
memcpy(pClipboardData, gClipboardData.c_str(), gClipboardData.length());
|
|
|
|
pClipboardData[gClipboardData.length() + 1] = 0x00;
|
|
|
|
|
|
|
|
GlobalUnlock(hClipboardData);
|
|
|
|
|
|
|
|
if (!OpenClipboard(NULL)) {
|
2015-05-02 20:13:24 +00:00
|
|
|
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
|
2015-05-02 22:28:40 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!EmptyClipboard()) {
|
|
|
|
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!SetClipboardData(CF_TEXT, hClipboardData)) {
|
|
|
|
result = "SetClipboardData() failed, GetLastError=" + GetLastError();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!CloseClipboard()) {
|
|
|
|
result = "CloseClipboard() failed, GetLastError=" + GetLastError();
|
|
|
|
}
|
2015-05-02 21:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-02 22:28:40 +00:00
|
|
|
|
|
|
|
gClipboardData = "";
|
|
|
|
} else {
|
|
|
|
gClipboardData = gClipboardData + cur_input;
|
2015-05-02 21:18:42 +00:00
|
|
|
}
|
|
|
|
|
2015-05-02 22:28:40 +00:00
|
|
|
end:
|
|
|
|
if(result.length() > 1)
|
|
|
|
memcpy(output, result.c_str(), result.length()+1);
|
2015-05-02 21:18:42 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 15:34:14 +00:00
|
|
|
EXTENSION_RETURN();
|
2015-05-02 21:18:42 +00:00
|
|
|
}
|
|
|
|
|