1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
case IDM_PASTE:
if(fOpen == false) //Check for open file
return 0;
if (!IsClipboardFormatAvailable(CF_TEXT)){
MessageBox(hwnd, "Format not available", "Paste Error", MB_OK);
return 0;
}
if(!OpenClipboard(hwnd)){
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Paste Error",
MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
break;
}
hClpData = GetClipboardData(CF_TEXT); // This is where I get an error
if (hClpData != NULL){
MemSize = GlobalSize(hClpData); // Get size of global memory
if(MemSize == 0){ // Size is 0, and last error is Invalid Handle.
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Memory Error",
MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
return 0;
}
ClpBdDataPtr = (CHAR*)GlobalLock(hClpData);
if (ClpBdDataPtr == NULL){ // I get the same error here
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Paste Error",
MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
return 0;
}
char *PasteBuff = new char [MemSize + 1]; // create a new
memcpy(PasteBuff, ClpBdDataPtr, MemSize); // buffer and copy data.
GlobalUnlock(hClpData);
// Call function to insert the text and repaint the window.
PasteHex(PasteBuff, nCaretPos);
delete [] PasteBuff; //delete the buffer;
}
CloseClipboard();
return 0;
|