📄 bindctx.c
字号:
* BindCtx_GetRunningObjectTable
******************************************************************************/
static HRESULT WINAPI
BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot)
{
HRESULT res;
BindCtxImpl *This = (BindCtxImpl *)iface;
TRACE("(%p,%p)\n",This,pprot);
if (pprot==NULL)
return E_POINTER;
res=GetRunningObjectTable(0, pprot);
return res;
}
/******************************************************************************
* BindCtx_RegisterObjectParam
******************************************************************************/
static HRESULT WINAPI
BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk)
{
DWORD index=0;
BindCtxImpl *This = (BindCtxImpl *)iface;
TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk);
if (punk==NULL)
return E_INVALIDARG;
if (pszkey!=NULL && BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_OK)
{
TRACE("Overwriting existing key\n");
if(This->bindCtxTable[index].pObj!=NULL)
IUnknown_Release(This->bindCtxTable[index].pObj);
This->bindCtxTable[index].pObj=punk;
IUnknown_AddRef(punk);
return S_OK;
}
This->bindCtxTable[This->bindCtxTableLastIndex].pObj = punk;
This->bindCtxTable[This->bindCtxTableLastIndex].regType = 1;
if (pszkey==NULL)
This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=NULL;
else
{
This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=
HeapAlloc(GetProcessHeap(),0,(sizeof(WCHAR)*(1+lstrlenW(pszkey))));
if (This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj==NULL)
return E_OUTOFMEMORY;
lstrcpyW(This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj,pszkey);
}
This->bindCtxTableLastIndex++;
if (This->bindCtxTableLastIndex == This->bindCtxTableSize)
{
/* table is full ! must be resized */
This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */
if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE))
{
FIXME("This->bindCtxTableSize: %ld is out of data limite\n", This->bindCtxTableSize);
return E_FAIL;
}
This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable,
This->bindCtxTableSize * sizeof(BindCtxObject));
if (!This->bindCtxTable)
return E_OUTOFMEMORY;
}
IUnknown_AddRef(punk);
return S_OK;
}
/******************************************************************************
* BindCtx_GetObjectParam
******************************************************************************/
static HRESULT WINAPI
BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk)
{
DWORD index;
BindCtxImpl *This = (BindCtxImpl *)iface;
TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk);
if (punk==NULL)
return E_POINTER;
*punk=0;
if (BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_FALSE)
return E_FAIL;
IUnknown_AddRef(This->bindCtxTable[index].pObj);
*punk = This->bindCtxTable[index].pObj;
return S_OK;
}
/******************************************************************************
* BindCtx_RevokeObjectParam
******************************************************************************/
static HRESULT WINAPI
BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR ppenum)
{
DWORD index,j;
BindCtxImpl *This = (BindCtxImpl *)iface;
TRACE("(%p,%s)\n",This,debugstr_w(ppenum));
if (BindCtxImpl_GetObjectIndex(This,NULL,ppenum,&index)==S_FALSE)
return E_FAIL;
/* release the object if it's found */
if(This->bindCtxTable[index].pObj)
IUnknown_Release(This->bindCtxTable[index].pObj);
HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj);
/* remove the object from the table with a left-shifting of all objects in the right side */
for(j=index; j<This->bindCtxTableLastIndex-1; j++)
This->bindCtxTable[j]= This->bindCtxTable[j+1];
This->bindCtxTableLastIndex--;
return S_OK;
}
/******************************************************************************
* BindCtx_EnumObjectParam
******************************************************************************/
static HRESULT WINAPI
BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** pszkey)
{
FIXME("(%p,%p),stub!\n",iface,pszkey);
return E_NOTIMPL;
}
/********************************************************************************
* GetObjectIndex (local function)
********************************************************************************/
static HRESULT BindCtxImpl_GetObjectIndex(BindCtxImpl* This,
IUnknown* punk,
LPOLESTR pszkey,
DWORD *index)
{
DWORD i;
BYTE found=0;
TRACE("(%p,%p,%p,%p)\n",This,punk,pszkey,index);
if (punk==NULL)
/* search object identified by a register key */
for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++)
{
if(This->bindCtxTable[i].regType==1){
if ( ( (This->bindCtxTable[i].pkeyObj==NULL) && (pszkey==NULL) ) ||
( (This->bindCtxTable[i].pkeyObj!=NULL) &&
(pszkey!=NULL) &&
(lstrcmpW(This->bindCtxTable[i].pkeyObj,pszkey)==0)
)
)
found=1;
}
}
else
/* search object identified by a moniker*/
for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++)
if(This->bindCtxTable[i].pObj==punk)
found=1;
if (index != NULL)
*index=i-1;
if (found)
return S_OK;
TRACE("key not found\n");
return S_FALSE;
}
/* Virtual function table for the BindCtx class. */
static const IBindCtxVtbl VT_BindCtxImpl =
{
BindCtxImpl_QueryInterface,
BindCtxImpl_AddRef,
BindCtxImpl_Release,
BindCtxImpl_RegisterObjectBound,
BindCtxImpl_RevokeObjectBound,
BindCtxImpl_ReleaseBoundObjects,
BindCtxImpl_SetBindOptions,
BindCtxImpl_GetBindOptions,
BindCtxImpl_GetRunningObjectTable,
BindCtxImpl_RegisterObjectParam,
BindCtxImpl_GetObjectParam,
BindCtxImpl_EnumObjectParam,
BindCtxImpl_RevokeObjectParam
};
/******************************************************************************
* BindCtx_Construct (local function)
*******************************************************************************/
static HRESULT BindCtxImpl_Construct(BindCtxImpl* This)
{
TRACE("(%p)\n",This);
/* Initialize the virtual function table.*/
This->lpVtbl = &VT_BindCtxImpl;
This->ref = 0;
/* Initialize the BIND_OPTS2 structure */
This->bindOption2.cbStruct = sizeof(BIND_OPTS2);
This->bindOption2.grfFlags = 0;
This->bindOption2.grfMode = STGM_READWRITE;
This->bindOption2.dwTickCountDeadline = 0;
This->bindOption2.dwTrackFlags = 0;
This->bindOption2.dwClassContext = CLSCTX_SERVER;
This->bindOption2.locale = 1033;
This->bindOption2.pServerInfo = 0;
/* Initialize the bindctx table */
This->bindCtxTableSize=BLOCK_TAB_SIZE;
This->bindCtxTableLastIndex=0;
This->bindCtxTable = HeapAlloc(GetProcessHeap(), 0,
This->bindCtxTableSize*sizeof(BindCtxObject));
if (This->bindCtxTable==NULL)
return E_OUTOFMEMORY;
return S_OK;
}
/******************************************************************************
* CreateBindCtx (OLE32.@)
******************************************************************************/
HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC * ppbc)
{
BindCtxImpl* newBindCtx = 0;
HRESULT hr;
IID riid=IID_IBindCtx;
TRACE("(%ld,%p)\n",reserved,ppbc);
newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl));
if (newBindCtx == 0)
return E_OUTOFMEMORY;
hr = BindCtxImpl_Construct(newBindCtx);
if (FAILED(hr))
{
HeapFree(GetProcessHeap(),0,newBindCtx);
return hr;
}
hr = BindCtxImpl_QueryInterface((IBindCtx*)newBindCtx,&riid,(void**)ppbc);
return hr;
}
HRESULT WINAPI BindMoniker(LPMONIKER pmk, DWORD grfOpt, REFIID riid, LPVOID * ppvResult)
{
HRESULT res;
IBindCtx * pbc;
TRACE("(%p, %lx, %s, %p)\n", pmk, grfOpt, debugstr_guid(riid), ppvResult);
res = CreateBindCtx(grfOpt, &pbc);
if (SUCCEEDED(res))
res = IMoniker_BindToObject(pmk, pbc, NULL, riid, ppvResult);
return res;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -