Basically I'm just trying to read regular text (CF_TEXT) from the Windows clipboard but as soon as I pass the handle to GlobalLock, it crashes. No errors are being thrown when compiling and this code should work. Any ideas? =D Sample code below.
INLINE
DECLARE(IsClipboardFormatAvailable,"user32.dll",(int),int);
DECLARE(GetClipboardData,"user32.dll",(int),int);
DECLARE(OpenClipboard,"user32.dll",(void*),int);
DECLARE(CloseClipboard,"user32.dll",(void),int);
DECLARE(GlobalLock,"kernal32.dll",(int),int);
DECLARE(GlobalUnlock,"kernal32.dll",(int),int);
ENDINLINE
FUNCTION get_clipboard:
INLINE
HANDLE hData;
if(IsClipboardFormatAvailable(1) && OpenClipboard(GLBASIC_HWND()))
{
hData = GetClipboardData(1);
if(hData != NULL)
{
char *clipboard_data = (char*) GlobalLock(hData);
GlobalUnlock(hData);
}
CloseClipboard();
}
ENDINLINE
ENDFUNCTION
Thank you for reminding me. I wrote a cross platform Clipboard library once:
http://www.glbasic.com/showroom.php?game=clipboard (http://www.glbasic.com/showroom.php?game=clipboard)
Edit:
BTW, here's how I did it for Win32:
::EmptyClipboard();
// ::SetClipboardData(CF_TEXT, (void*)text_Str.c_str());
int cch = LEN(text_Str);
void* hglbCopy = ::GlobalAlloc(GMEM_MOVEABLE, cch+1);
if (hglbCopy)
{
// Lock the handle and copy the text to the buffer.
char* lptstrCopy = (char*)GlobalLock(hglbCopy);
for(int n=0; n<=cch; ++n)
{
lptstrCopy[n] = text_Str[n];
}
lptstrCopy[cch] = '\0';
GlobalUnlock(hglbCopy);
SetClipboardData(CF_TEXT, hglbCopy);
}
::CloseClipboard();
Oh excellent, I was also already looking into this for Linux as well. Looks like you just saved me some time. XD