'Saving struct to clipboard in C++

I have this structure in my C++ code:

struct sData
{
    DWORD Number;
    int CurrentNumber;
    bool GameOver;
};

I need to save it to Clipboard as a structure from one process. And from other process I need to load it again as the structure. I can do it easy with Cstrings/strings but not with structures. What do you suggest to me?

This is my method for setting Cstring to Clipboard:

bool SetText(CString text)
    {
        CString  source;
        source = text;
        //put your text in source
        if (OpenClipboard(NULL))
        {
            HGLOBAL clipbuffer;
            char * buffer;
            EmptyClipboard();
            clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength() + 1);
            buffer = (char*)GlobalLock(clipbuffer);
            strcpy(buffer, LPCSTR(source));
            GlobalUnlock(clipbuffer);
            SetClipboardData(CF_TEXT, clipbuffer);
            CloseClipboard();
            return true;
        }
        else
        {
            return false;
        }
    }

And this is getter:

std::string GetText(void) const
    {
        return (const char*)GetClipboardData(CF_TEXT);
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source