2016-05-30 16:37:03 +00:00
|
|
|
/*
|
|
|
|
* ace_clipboard.cpp
|
|
|
|
*
|
2016-06-12 15:35:19 +00:00
|
|
|
* Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit. Windows only.
|
2016-05-30 16:37:03 +00:00
|
|
|
*
|
|
|
|
* Takes:
|
|
|
|
* Localized string as string
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* None
|
|
|
|
*/
|
2016-06-12 15:35:19 +00:00
|
|
|
|
2016-05-30 16:37:03 +00:00
|
|
|
#include "shared.hpp"
|
2016-06-12 15:35:19 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2016-05-30 16:37:03 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
EXPORT void __stdcall RVExtension(char *output, int outputSize, const char *function);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string gClipboardData;
|
|
|
|
|
|
|
|
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
|
|
|
|
std::string cur_input(function);
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
ZERO_OUTPUT();
|
|
|
|
|
|
|
|
if (cur_input.length() < 1) {
|
|
|
|
EXTENSION_RETURN();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(function, "version")) {
|
2020-04-18 17:41:37 +00:00
|
|
|
std::strncpy(output, ACE_FULL_VERSION_STR, outputSize - 1);
|
2016-05-30 16:37:03 +00:00
|
|
|
EXTENSION_RETURN();
|
|
|
|
}
|
|
|
|
|
2016-06-12 15:35:19 +00:00
|
|
|
#ifdef _WIN32
|
2016-05-30 16:37:03 +00:00
|
|
|
|
|
|
|
if (!strcmp(function, "--COMPLETE--")) {
|
2016-06-12 15:35:19 +00:00
|
|
|
if (OpenClipboard(NULL) == 0) {
|
2016-05-30 16:37:03 +00:00
|
|
|
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
|
2016-06-12 15:35:19 +00:00
|
|
|
} else {
|
|
|
|
if (EmptyClipboard() == 0) {
|
|
|
|
result = "EmptyClipboard() failed, GetLastError=" + GetLastError();
|
|
|
|
} else {
|
|
|
|
// GPTR = GMEM_FIXED + GMEM_ZEROINIT, returns a ptr, no need for GlobalLock/GlobalUnlock
|
|
|
|
char *pClipboardData = (char *)GlobalAlloc(GPTR, gClipboardData.length());
|
|
|
|
|
|
|
|
if (pClipboardData == NULL) {
|
|
|
|
result = "GlobalAlloc() failed, GetLastError=" + GetLastError();
|
|
|
|
EXTENSION_RETURN();
|
2016-05-30 16:37:03 +00:00
|
|
|
}
|
2019-09-28 21:03:55 +00:00
|
|
|
strncpy(pClipboardData, gClipboardData.c_str(), gClipboardData.length());
|
2016-06-12 15:35:19 +00:00
|
|
|
|
|
|
|
// if success, system owns the memory, if fail, free it from the heap
|
|
|
|
if (SetClipboardData(CF_TEXT, pClipboardData) == NULL) {
|
|
|
|
result = "SetClipboardData() failed, GetLastError=" + GetLastError();
|
|
|
|
GlobalFree(pClipboardData);
|
|
|
|
} else {
|
|
|
|
if (CloseClipboard() == 0) {
|
2016-05-30 16:37:03 +00:00
|
|
|
result = "CloseClipboard() failed, GetLastError=" + GetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gClipboardData = "";
|
|
|
|
} else {
|
|
|
|
gClipboardData = gClipboardData + cur_input;
|
|
|
|
}
|
|
|
|
|
2016-06-12 15:35:19 +00:00
|
|
|
if (result.length() > 1) {
|
2020-04-18 17:41:37 +00:00
|
|
|
strncpy(output, result.c_str(), outputSize - 1);
|
2016-06-12 15:35:19 +00:00
|
|
|
}
|
2016-05-30 16:37:03 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXTENSION_RETURN();
|
|
|
|
}
|