本文整理汇总了C++中ReleaseStgMedium函数的典型用法代码示例。如果您正苦于以下问题:C++ ReleaseStgMedium函数的具体用法?C++ ReleaseStgMedium怎么用?C++ ReleaseStgMedium使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReleaseStgMedium函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getURL
String getURL(IDataObject* dataObject, bool& success, String* title)
{
STGMEDIUM store;
String url;
success = false;
if (getWebLocData(dataObject, url, title)) {
success = true;
return url;
} else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) {
//URL using unicode
UChar* data = (UChar*)GlobalLock(store.hGlobal);
url = extractURL(String(data), title);
GlobalUnlock(store.hGlobal);
ReleaseStgMedium(&store);
success = true;
} else if (SUCCEEDED(dataObject->GetData(urlFormat(), &store))) {
//URL using ascii
char* data = (char*)GlobalLock(store.hGlobal);
url = extractURL(String(data), title);
GlobalUnlock(store.hGlobal);
ReleaseStgMedium(&store);
success = true;
} else if (SUCCEEDED(dataObject->GetData(filenameWFormat(), &store))) {
//file using unicode
wchar_t* data = (wchar_t*)GlobalLock(store.hGlobal);
if (data && data[0] && (PathFileExists(data) || PathIsUNC(data))) {
RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar*)data, wcslen(data)));
if (urlFromPath(pathAsCFString.get(), url)) {
if (title)
*title = url;
success = true;
}
}
GlobalUnlock(store.hGlobal);
ReleaseStgMedium(&store);
} else if (SUCCEEDED(dataObject->GetData(filenameFormat(), &store))) {
//filename using ascii
char* data = (char*)GlobalLock(store.hGlobal);
if (data && data[0] && (PathFileExistsA(data) || PathIsUNCA(data))) {
RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCString(kCFAllocatorDefault, data, kCFStringEncodingASCII));
if (urlFromPath(pathAsCFString.get(), url)) {
if (title)
*title = url;
success = true;
}
}
GlobalUnlock(store.hGlobal);
ReleaseStgMedium(&store);
}
return url;
}
示例2: GlobalLock
STDMETHODIMP CFdmUplSendToShlExt::DragEnter (IDataObject* pDataObj, DWORD grfKeyState,
POINTL pt, DWORD* pdwEffect)
{
*pdwEffect = DROPEFFECT_NONE;
FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stg = { TYMED_HGLOBAL };
HDROP hDrop;
if (FAILED (pDataObj->GetData (&fmt, &stg)))
return E_INVALIDARG;
hDrop = (HDROP) GlobalLock (stg.hGlobal);
if (hDrop == NULL)
return E_INVALIDARG;
int cFiles = DragQueryFile (hDrop, 0xFFFFFFFF, NULL, 0);
if (cFiles == 0)
{
GlobalUnlock (stg.hGlobal);
ReleaseStgMedium (&stg);
return E_INVALIDARG;
}
for (int i = 0; i < cFiles; i++)
{
char szFile [MAX_PATH];
if (0 == DragQueryFile (hDrop, i, szFile, MAX_PATH))
continue;
DWORD dwAttribs = GetFileAttributes (szFile);
if (dwAttribs == DWORD (-1))
continue;
m_vFiles.push_back (szFile);
}
GlobalUnlock (stg.hGlobal);
ReleaseStgMedium (&stg);
if (m_vFiles.size () == 0)
return E_INVALIDARG;
*pdwEffect = DROPEFFECT_COPY;
return S_OK;
}
示例3: GlobalLock
// CSimpleShlExt
//我们要做的是取得被右击选择的文件名,再把该文件名显示在弹出消息框中。
//可能会有多个文件同时被选择右击, 你可以用pDataObj 接口指针获取所有的文件名, 但现在为简单起见, 我们只获取第一个文件名.
//add by ray 2014-05-15 17:45
HRESULT CSimpleShlExt::Initialize ( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hProgID )
{
//文件名的存放格式与你拖放文件到带WS_EX_ACCEPTFILES风格的窗口时使用的文件名格式是一样的。
// 这就是说我们可以使用同样的API来获取文件名: DragQueryFile().
// 首先我们先获取包含在IdataObject中的数据句柄:
FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stg = { TYMED_HGLOBAL };
HDROP hDrop;
// 在数据对象内查找 CF_HDROP 型数据.
if ( FAILED( pDataObj->GetData ( &fmt, &stg )))
{
// Nope! Return an "invalid argument" error back to Explorer.
return E_INVALIDARG;
}
// 获得指向实际数据的指针
hDrop = (HDROP) GlobalLock ( stg.hGlobal );
// 检查非NULL.
if ( NULL == hDrop )
{
return E_INVALIDARG;
}
//请注意错误检查,特别是指针的检查。
// 由于我们的扩展运行在 Explorer 进程内, 要是我们的代码崩溃了, Explorer也会随之崩溃. 在Win 9x上, 这样的一个崩溃可能导致需要重启系统.
// 所以, 现在我们有了一个 HDROP 句柄, 我们就可以获取我们需要的文件名了:
// 有效性检查 – 保证最少有一个文件名.
UINT uNumFiles = DragQueryFile ( hDrop, 0xFFFFFFFF, NULL, 0 );
if ( 0 == uNumFiles )
{
GlobalUnlock ( stg.hGlobal );
ReleaseStgMedium ( &stg );
return E_INVALIDARG;
}
HRESULT hr = S_OK;
// 取得第一个文件名并把它保存在类成员m_szFile 中.
if ( 0 == DragQueryFile ( hDrop, 0, m_szFile, MAX_PATH ))
{
hr = E_INVALIDARG;
}
GlobalUnlock ( stg.hGlobal );
ReleaseStgMedium ( &stg );
return hr;
}
示例4: DCHECK
bool ClipboardUtil::GetUrl(IDataObject* data_object, std::wstring* url,
std::wstring* title, bool convert_filenames)
{
DCHECK(data_object && url && title);
if(!HasUrl(data_object))
{
return false;
}
// 尝试从|data_object|的多种格式中提取URL.
STGMEDIUM store;
if(GetUrlFromHDrop(data_object, url, title))
{
return true;
}
if(SUCCEEDED(data_object->GetData(GetMozUrlFormat(), &store)) ||
SUCCEEDED(data_object->GetData(GetUrlWFormat(), &store)))
{
{
// Mozilla URL格式或者unicode URL.
base::win::ScopedHGlobal<wchar_t> data(store.hGlobal);
SplitUrlAndTitle(data.get(), url, title);
}
ReleaseStgMedium(&store);
return true;
}
if(SUCCEEDED(data_object->GetData(GetUrlFormat(), &store)))
{
{
// URL使用ascii.
base::win::ScopedHGlobal<char> data(store.hGlobal);
SplitUrlAndTitle(UTF8ToWide(data.get()), url, title);
}
ReleaseStgMedium(&store);
return true;
}
if(convert_filenames)
{
return GetFileUrl(data_object, url, title);
}
else
{
return false;
}
}
示例5: RegisterClipboardFormat
STDMETHODIMP CShellPropSheetExt::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
{
HRESULT hr;
FORMATETC formatetc;
STGMEDIUM medium;
LPTSTR lpszFilePath;
formatetc.cfFormat = RegisterClipboardFormat(CFSTR_FILENAME);
formatetc.ptd = NULL;
formatetc.dwAspect = DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.tymed = TYMED_HGLOBAL;
hr = pdtobj->GetData(&formatetc, &medium);
if (FAILED(hr))
return E_FAIL;
lpszFilePath = (LPTSTR)GlobalLock(medium.hGlobal);
filepath = lpszFilePath;
GlobalUnlock(medium.hGlobal);
ReleaseStgMedium(&medium);
return S_OK;
}
示例6: ReleaseStgMedium
HRESULT CDropTarget::GetDroppedFiles(IDataObject *lpDataObject,std::list<CString> &fileList)
{
FORMATETC fmt;
STGMEDIUM medium;
fmt.cfFormat = CF_HDROP;
fmt.ptd = NULL;
fmt.dwAspect = DVASPECT_CONTENT;
fmt.lindex = -1;
fmt.tymed = TYMED_HGLOBAL;
fileList.clear();
HRESULT hr=lpDataObject->GetData(&fmt, &medium);
if(S_OK==hr){
//ファイルがドロップされた
//---ファイル数を取得
UINT nFileCount = ::DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0);
//ファイル取得
for(UINT i=0; i<nFileCount;i++){
TCHAR szBuffer[_MAX_PATH+2]={0};
::DragQueryFile((HDROP)medium.hGlobal, i, szBuffer, _MAX_PATH + 1);
fileList.push_back(szBuffer);
}
//解放
ReleaseStgMedium(&medium);
return S_OK;
}else{
return hr;
}
}
示例7: CopyBindInfo
/***********************************************************************
* CopyBindInfo ([email protected])
*/
HRESULT WINAPI CopyBindInfo(const BINDINFO *pcbiSrc, BINDINFO *pcbiDest)
{
DWORD size;
HRESULT hres;
TRACE("(%p %p)\n", pcbiSrc, pcbiDest);
if(!pcbiSrc || !pcbiDest)
return E_POINTER;
if(!pcbiSrc->cbSize || !pcbiDest->cbSize)
return E_INVALIDARG;
size = pcbiDest->cbSize;
if(size > pcbiSrc->cbSize) {
memcpy(pcbiDest, pcbiSrc, pcbiSrc->cbSize);
memset((char*)pcbiDest+pcbiSrc->cbSize, 0, size-pcbiSrc->cbSize);
} else {
memcpy(pcbiDest, pcbiSrc, size);
}
pcbiDest->cbSize = size;
size = FIELD_OFFSET(BINDINFO, szExtraInfo)+sizeof(void*);
if(pcbiSrc->cbSize>=size && pcbiDest->cbSize>=size && pcbiSrc->szExtraInfo) {
size = (strlenW(pcbiSrc->szExtraInfo)+1)*sizeof(WCHAR);
pcbiDest->szExtraInfo = CoTaskMemAlloc(size);
if(!pcbiDest->szExtraInfo)
return E_OUTOFMEMORY;
memcpy(pcbiDest->szExtraInfo, pcbiSrc->szExtraInfo, size);
}
size = FIELD_OFFSET(BINDINFO, stgmedData)+sizeof(STGMEDIUM);
if(pcbiSrc->cbSize>=size && pcbiDest->cbSize>=size) {
hres = CopyStgMedium(&pcbiSrc->stgmedData, &pcbiDest->stgmedData);
if(FAILED(hres)) {
CoTaskMemFree(pcbiDest->szExtraInfo);
return hres;
}
}
size = FIELD_OFFSET(BINDINFO, szCustomVerb)+sizeof(void*);
if(pcbiSrc->cbSize>=size && pcbiDest->cbSize>=size && pcbiSrc->szCustomVerb) {
size = (strlenW(pcbiSrc->szCustomVerb)+1)*sizeof(WCHAR);
pcbiDest->szCustomVerb = CoTaskMemAlloc(size);
if(!pcbiDest->szCustomVerb) {
CoTaskMemFree(pcbiDest->szExtraInfo);
ReleaseStgMedium(&pcbiDest->stgmedData);
return E_OUTOFMEMORY;
}
memcpy(pcbiDest->szCustomVerb, pcbiSrc->szCustomVerb, size);
}
size = FIELD_OFFSET(BINDINFO, securityAttributes)+sizeof(SECURITY_ATTRIBUTES);
if(pcbiDest->cbSize >= size)
memset(&pcbiDest->securityAttributes, 0, sizeof(SECURITY_ATTRIBUTES));
if(pcbiSrc->pUnk)
IUnknown_AddRef(pcbiDest->pUnk);
return S_OK;
}
示例8: UNREFERENCED_PARAMETER
HRESULT __stdcall CBookmarksToolbarDropHandler::DragEnter(IDataObject *pDataObject,
DWORD grfKeyState,POINTL pt,DWORD *pdwEffect)
{
UNREFERENCED_PARAMETER(grfKeyState);
bool m_bValid = false;
bool m_bAllFolders = true;
FORMATETC ftc = {CF_HDROP,0,DVASPECT_CONTENT,-1,TYMED_HGLOBAL};
STGMEDIUM stg;
HRESULT hr = pDataObject->GetData(&ftc,&stg);
if(hr == S_OK)
{
DROPFILES *pdf = reinterpret_cast<DROPFILES *>(GlobalLock(stg.hGlobal));
if(pdf != NULL)
{
m_bValid = true;
UINT nDroppedFiles = DragQueryFile(reinterpret_cast<HDROP>(pdf),0xFFFFFFFF,NULL,NULL);
for(UINT i = 0;i < nDroppedFiles;i++)
{
TCHAR szFullFileName[MAX_PATH];
DragQueryFile(reinterpret_cast<HDROP>(pdf),i,szFullFileName,
SIZEOF_ARRAY(szFullFileName));
if(!PathIsDirectory(szFullFileName))
{
m_bAllFolders = false;
break;
}
}
GlobalUnlock(stg.hGlobal);
}
ReleaseStgMedium(&stg);
}
if(m_bValid &&
m_bAllFolders)
{
*pdwEffect = DROPEFFECT_COPY;
m_bAcceptData = true;
}
else
{
*pdwEffect = DROPEFFECT_NONE;
m_bAcceptData = false;
}
m_pDropTargetHelper->DragEnter(m_hToolbar,pDataObject,reinterpret_cast<POINT *>(&pt),*pdwEffect);
return S_OK;
}
示例9: printf
//IDropTarget methods
STDMETHODIMP CDropTarget::DragEnter(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
{
#ifdef _DEBUG
printf("IDropTarget::DragEnter\n");
#endif //_DEBUG
pDataObj = pDataObject;
pDataObject->AddRef();
hdrop_present = false;
if (hexwnd.prefer_CF_HDROP)
{
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, 0xffffffff };
STGMEDIUM stm;
if (S_OK == pDataObject->QueryGetData(&fe))
{
hdrop_present = true;
*pdwEffect = DROPEFFECT_COPY;
return S_OK;
}
else if (S_OK == pDataObject->GetData(&fe, &stm))
{
hdrop_present = true;
ReleaseStgMedium(&stm);
*pdwEffect = DROPEFFECT_COPY;
return S_OK;
}
}
hexwnd.pwnd->CreateCaret((HBITMAP)1, 2, hexwnd.cyChar);
return DragOver(grfKeyState, pt, pdwEffect);
}
示例10: getDropData
void
getDropData(IDataObject* dataObject)
{
// construct a FORMATETC object
FORMATETC fmtEtc = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stgMed;
// See if the dataobject contains any DROP stored as a HGLOBAL
if (dataObject->QueryGetData(&fmtEtc) == S_OK) {
if (dataObject->GetData(&fmtEtc, &stgMed) == S_OK) {
// get data here
PVOID data = GlobalLock(stgMed.hGlobal);
// data object global handler contains:
// DROPFILESfilename1 filename2 two spaces as the end
// TODO: get multiple filenames
wchar_t* wcData = (wchar_t*)((LPBYTE)data + sizeof(DROPFILES));
// convert wchar to char
char* filename = new char[wcslen(wcData) + 1];
filename[wcslen(wcData)] = '\0';
wcstombs(filename, wcData, wcslen(wcData));
MSWindowsDropTarget::instance().setDraggingFilename(filename);
GlobalUnlock(stgMed.hGlobal);
// release the data using the COM API
ReleaseStgMedium(&stgMed);
delete[] filename;
}
}
}
示例11: SetVariantData
///////////////////////////////////////////////////////////////////////////////
// Schreiben/Lesen eines Variant
HRESULT SetVariantData (CComVariant &rv, IDataObject *pIDO, const FORMATETC *pcfe)
{
// Stream mit Variant generieren
WStream IStream;
HRESULT hr = CreateStreamOnHGlobal (NULL, true, IStream.ppi());
if (FAILED(hr)) return hr;
// Variant dort rein schreiben
hr = rv.WriteToStream (IStream);
if (FAILED(hr)) return hr;
LARGE_INTEGER li;
LISet32(li, 0L);
hr = IStream -> Seek (li, SEEK_SET, NULL);
if (FAILED(hr)) return hr;
// diesen Stream im DataObject setzen
STGMEDIUM stg;
stg.tymed = TYMED_ISTREAM;
stg.pstm = IStream.detach();
stg.pUnkForRelease = NULL;
hr = pIDO -> SetData ((FORMATETC *)pcfe, &stg, true);
if (FAILED(hr)) {
ReleaseStgMedium (&stg);
return hr;
}
return S_OK;
}
示例12: ReleaseStgMedium
//
// IDataObject::SetData
//
HRESULT __stdcall CDataObject::SetData (FORMATETC *pFormatEtc, STGMEDIUM *pMedium, BOOL fRelease)
{
int res=LookupFormatEtc(pFormatEtc, pMedium, TRUE);
if(-1 == res)
{
return S_FALSE;
}
if (m_pStgMedium[res].tymed)
{
ReleaseStgMedium ( &m_pStgMedium[res] );
ZeroMemory (&m_pStgMedium[res], sizeof(STGMEDIUM) );
}
if(fRelease)
{
m_pStgMedium[res]=*pMedium;
}
else
{
CopyStgMedium(pMedium, &m_pStgMedium[res]);
}
m_pFormatEtc[res].tymed=m_pStgMedium[res].tymed;
if(m_pStgMedium[res].tymed==TYMED_HGLOBAL)
{
m_pStgMedium[res].hGlobal=DupMem(pMedium->hGlobal);//必须分配足够的内存空间和拷贝数据。
}
if(GetCanonicalIUnknown(m_pStgMedium[res].pUnkForRelease)==
GetCanonicalIUnknown(static_cast<IDataObject*>(this)))
{
m_pStgMedium[res].pUnkForRelease->Release();
m_pStgMedium[res].pUnkForRelease = NULL;
}
return S_OK;
}
示例13: DragLeave
STDMETHODIMP CToolBarCombo::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect){
*pdwEffect=DROPEFFECT_NONE;
if (m_pIDataObject == NULL)
return E_FAIL;
DragLeave();
FORMATETC formatDetails;
STGMEDIUM stmg;
// Let's get the text from the "clipboard"
formatDetails.cfFormat = CF_TEXT;
formatDetails.dwAspect = DVASPECT_CONTENT;
formatDetails.lindex = -1;
formatDetails.ptd = NULL;
formatDetails.tymed = TYMED_HGLOBAL;
if (SUCCEEDED(pDataObj->GetData(&formatDetails, &stmg)))
{
char* sClipboard = (char*)GlobalLock(stmg.hGlobal);
::SetWindowTextA(m_hWnd,sClipboard);
AddtoHistory(sClipboard);
GlobalUnlock(stmg.hGlobal);
if (stmg.hGlobal != NULL)
ReleaseStgMedium(&stmg);
}
*pdwEffect=DROPEFFECT_COPY;
//search immediately after dragging
::PostMessage(GetParent(),kWM_TBCOMBOSEARCH_WEB, 0, 0);
return NOERROR;
}
示例14: GlobalUnlock
STDMETHODIMP CToolBarCombo::DragEnter(LPDATAOBJECT pDataObj , DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect){
m_pIDataObject=NULL;
ATL::CString sText;
FORMATETC formatDetails;
STGMEDIUM stmg;
// Let's get the text from the "clipboard"
formatDetails.cfFormat = CF_TEXT;
formatDetails.dwAspect = DVASPECT_CONTENT;
formatDetails.lindex = -1;
formatDetails.ptd = NULL;
formatDetails.tymed = TYMED_HGLOBAL;
if (SUCCEEDED(pDataObj->GetData(&formatDetails, &stmg)))
{
sText = (LPSTR)GlobalLock(stmg.hGlobal);
GlobalUnlock(stmg.hGlobal);
if (stmg.hGlobal != NULL)
ReleaseStgMedium(&stmg);
}
*pdwEffect=DROPEFFECT_COPY;
m_pIDataObject=pDataObj;
m_pIDataObject->AddRef();
return NOERROR;
}
示例15: ReleaseStgMedium
ClipboardReader::~ClipboardReader()
{
if (stgmed.hGlobal)
ReleaseStgMedium(&stgmed);
if (pDataObj)
pDataObj->Release();
}