diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-10-22 23:07:11 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-10-22 23:07:11 +0300 |
commit | d94de204ce513b7be134ed7a1aa83295b89719ec (patch) | |
tree | 8729b3d675e2609e6ead330be15645e8351ccd24 /options.cpp | |
parent | 4951c262631885820d1bbde0ed1c3ceb8cb285b6 (diff) |
copy key to clipboard button
Diffstat (limited to 'options.cpp')
-rwxr-xr-x | options.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
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:
|