Cleaned up and patched ace_clipboard.

This commit is contained in:
looterz 2016-02-17 17:07:06 -06:00
parent 8b16912ad7
commit 051973a546

View File

@ -1,7 +1,7 @@
/*
* ace_clipboard.cpp
*
* Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit.
* Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit. Windows only.
*
* Takes:
* Localized string as string
@ -9,7 +9,10 @@
* Returns:
* None
*/
#include "shared.hpp"
#include <stdlib.h>
#include <vector>
#include <string>
@ -30,44 +33,56 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) {
}
if (!strcmp(function, "version")) {
strncpy(output, ACE_FULL_VERSION_STR, outputSize);
strncpy_s(output, outputSize, ACE_FULL_VERSION_STR, _TRUNCATE);
EXTENSION_RETURN();
}
#ifdef _WIN32
#ifndef _WIN32
EXTENSION_RETURN();
#endif
if (!strcmp(function, "--COMPLETE--")) {
if (!strcmp(function, "--COMPLETE--"))
{
HGLOBAL hClipboardData = GlobalAlloc(GMEM_FIXED, gClipboardData.length() + 1);
if (!hClipboardData) {
if (!hClipboardData)
{
result = "GlobalAlloc() failed, GetLastError=" + GetLastError();
gClipboardData = "";
EXTENSION_RETURN();
}
char *pClipboardData = (char *)GlobalLock(hClipboardData);
if (!pClipboardData) {
if (!pClipboardData)
{
result = "GlobalLock() failed, GetLastError=" + GetLastError();
gClipboardData = "";
EXTENSION_RETURN();
}
memcpy(pClipboardData, gClipboardData.c_str(), gClipboardData.length());
pClipboardData[gClipboardData.length() + 1] = 0x00;
strncpy_s(pClipboardData, gClipboardData.length(), gClipboardData.c_str(), _TRUNCATE);
GlobalUnlock(hClipboardData);
if (!OpenClipboard(NULL)) {
if (!OpenClipboard(NULL))
{
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
}
else {
if (!EmptyClipboard()) {
else
{
if (!EmptyClipboard())
{
result = "OpenClipboard() failed, GetLastError=" + GetLastError();
}
else {
if (!SetClipboardData(CF_TEXT, hClipboardData)) {
else
{
if (!SetClipboardData(CF_TEXT, hClipboardData))
{
result = "SetClipboardData() failed, GetLastError=" + GetLastError();
}
else {
if (!CloseClipboard()) {
else
{
if (!CloseClipboard())
{
result = "CloseClipboard() failed, GetLastError=" + GetLastError();
}
}
@ -75,16 +90,16 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) {
}
gClipboardData = "";
} else {
}
else
{
gClipboardData = gClipboardData + cur_input;
}
end:
if(result.length() > 1)
memcpy(output, result.c_str(), result.length()+1);
#endif
if (result.length() > 1)
{
strncpy_s(output, outputSize, result.c_str(), _TRUNCATE);
}
EXTENSION_RETURN();
}