I tried to uset IDataObject to put a some text to clipboard. But the GlobalUnlock fails. What I'm doing wrong?
IDataObject *obj;
HRESULT ret;
assert(S_OK == OleGetClipboard(&obj));
FORMATETC fmtetc = {0};
fmtetc.cfFormat = CF_TEXT;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.lindex = -1;
fmtetc.tymed = TYMED_HGLOBAL;
STGMEDIUM medium = {0};
medium.tymed = TYMED_HGLOBAL;
char* str = "string";
medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, strlen(str)+1);
char* pMem = (char*)GlobalLock(medium.hGlobal);
strcpy(pMem,str);
assert(GlobalUnlock(medium.hGlobal) != 0); // !!! ERROR
assert(S_OK == obj->SetData(&fmtetc,&medium,TRUE));
assert(S_OK == OleSetClipboard(obj));