From d94de204ce513b7be134ed7a1aa83295b89719ec Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 22 Oct 2011 23:07:11 +0300 Subject: copy key to clipboard button --- options.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'options.cpp') diff --git a/options.cpp b/options.cpp index 440e1be..825bd00 100755 --- a/options.cpp +++ b/options.cpp @@ -362,18 +362,40 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA mir_free(szKey); for(std::string::size_type i = str.find("\n"); i != std::string::npos; i = str.find("\n", i+2)) str.replace(i, 1, "\r\n"); - szKey = mir_strdup(str.c_str()); + HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.size() +1); + if(!hMem) + { + MessageBoxA(0, "Failed to alocate memory", "Error", MB_OK); + break; + } + szKey = (char*)GlobalLock(hMem); + if(!szKey) + { + char msg[64]; + mir_snprintf(msg, 127, "Failed to lock memory with error %d", GetLastError()); + MessageBoxA(0, msg, "Error", MB_OK); + GlobalFree(hMem); + } + memcpy(szKey, str.c_str(), str.size()); + szKey[str.size()] = '\0'; str.clear(); EmptyClipboard(); - if(!SetClipboardData(CF_TEXT, szKey)) + GlobalUnlock(hMem); + if(!SetClipboardData(CF_OEMTEXT, hMem)) { - mir_free(szKey); - MessageBoxA(0, "Error", "Failed to write to clipboard", MB_OK); + GlobalFree(hMem); + char msg[64]; + mir_snprintf(msg, 127, "Failed write to clipboard with error %d", GetLastError()); + MessageBoxA(0, msg, "Error", MB_OK); } CloseClipboard(); } else - MessageBoxA(0, "Error", "Failed to open clipboard", MB_OK); + { + char msg[64]; + mir_snprintf(msg, 127, "Failed to open clipboard with error %d", GetLastError()); + MessageBoxA(0, msg, "Error", MB_OK); + } } break; case IDC_LOG_FILE_SET: -- cgit v1.2.3