#include <windows.h>
#include <stdio.h>
#include <comdef.h>
#include <tchar.h>
long Copy(BSTR bstrResCode)
{
_bstr_t lpResCode = bstrResCode;
int strLen = _tcslen(lpResCode)+1;
OpenClipboard(NULL);
EmptyClipboard();
HANDLE hMem;
LPTSTR lpData;
hMem = GlobalAlloc(GMEM_DDESHARE, strLen);
lpData = (LPTSTR)GlobalLock(hMem);
lstrcpy((LPTSTR)lpData, lpResCode);
GlobalUnlock(hMem);
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
return S_OK;
}void main()
{
BSTR bstrdata=SysAllocString(L"test");
Copy(bstrdata);
SysFreeString(bstrdata);
}