| 1 | /***************************************************************************************
|
|---|
| 2 | * BindCtx implementation
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 1999 Noomen Hamza
|
|---|
| 5 | ***************************************************************************************/
|
|---|
| 6 |
|
|---|
| 7 | #include <string.h>
|
|---|
| 8 | #include <assert.h>
|
|---|
| 9 | #include "winerror.h"
|
|---|
| 10 | #include "winbase.h"
|
|---|
| 11 | #include "wine/unicode.h"
|
|---|
| 12 | #include "wine/obj_base.h"
|
|---|
| 13 | #include "wine/obj_misc.h"
|
|---|
| 14 | #include "wine/obj_storage.h"
|
|---|
| 15 | #include "wine/obj_moniker.h"
|
|---|
| 16 | #include "debugtools.h"
|
|---|
| 17 | #include "heap.h"
|
|---|
| 18 |
|
|---|
| 19 | #ifdef __WIN32OS2__
|
|---|
| 20 | #undef FIXME
|
|---|
| 21 | #undef TRACE
|
|---|
| 22 | #ifdef DEBUG
|
|---|
| 23 | #define TRACE WriteLog("OLE32: %s", __FUNCTION__); WriteLog
|
|---|
| 24 | #define FIXME WriteLog("FIXME OLE32: %s", __FUNCTION__); WriteLog
|
|---|
| 25 | #else
|
|---|
| 26 | #define TRACE 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
|
|---|
| 27 | #define FIXME 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
|
|---|
| 28 | #endif
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | DEFAULT_DEBUG_CHANNEL(ole);
|
|---|
| 32 |
|
|---|
| 33 | /* represent the first size table and it's increment block size */
|
|---|
| 34 | #define BLOCK_TAB_SIZE 10
|
|---|
| 35 | #define MAX_TAB_SIZE 0xFFFFFFFF
|
|---|
| 36 |
|
|---|
| 37 | /* data structure of the BindCtx table elements */
|
|---|
| 38 | typedef struct BindCtxObject{
|
|---|
| 39 |
|
|---|
| 40 | IUnknown* pObj; /* point on a bound object */
|
|---|
| 41 |
|
|---|
| 42 | LPOLESTR pkeyObj; /* key associated to this bound object */
|
|---|
| 43 |
|
|---|
| 44 | BYTE regType; /* registration type: 1 if RegisterObjectParam and 0 if RegisterObjectBound */
|
|---|
| 45 |
|
|---|
| 46 | } BindCtxObject;
|
|---|
| 47 |
|
|---|
| 48 | /* BindCtx data strucrture */
|
|---|
| 49 | typedef struct BindCtxImpl{
|
|---|
| 50 |
|
|---|
| 51 | ICOM_VFIELD(IBindCtx); /* VTable relative to the IBindCtx interface.*/
|
|---|
| 52 |
|
|---|
| 53 | ULONG ref; /* reference counter for this object */
|
|---|
| 54 |
|
|---|
| 55 | BindCtxObject* bindCtxTable; /* this is a table in which all bounded objects are stored*/
|
|---|
| 56 | DWORD bindCtxTableLastIndex; /* first free index in the table */
|
|---|
| 57 | DWORD bindCtxTableSize; /* size table */
|
|---|
| 58 |
|
|---|
| 59 | BIND_OPTS2 bindOption2; /* a structure which contains the bind options*/
|
|---|
| 60 |
|
|---|
| 61 | } BindCtxImpl;
|
|---|
| 62 |
|
|---|
| 63 | /* IBindCtx prototype functions : */
|
|---|
| 64 |
|
|---|
| 65 | /* IUnknown functions*/
|
|---|
| 66 | static HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject);
|
|---|
| 67 | static ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface);
|
|---|
| 68 | static ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface);
|
|---|
| 69 | /* IBindCtx functions */
|
|---|
| 70 | static HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk);
|
|---|
| 71 | static HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk);
|
|---|
| 72 | static HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface);
|
|---|
| 73 | static HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts);
|
|---|
| 74 | static HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts);
|
|---|
| 75 | static HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot);
|
|---|
| 76 | static HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk);
|
|---|
| 77 | static HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk);
|
|---|
| 78 | static HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** ppenum);
|
|---|
| 79 | static HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR pszkey);
|
|---|
| 80 | /* Local functions*/
|
|---|
| 81 | HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This);
|
|---|
| 82 | HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This);
|
|---|
| 83 | HRESULT WINAPI BindCtxImpl_GetObjectIndex(BindCtxImpl* This,IUnknown* punk,LPOLESTR pszkey,DWORD *index);
|
|---|
| 84 |
|
|---|
| 85 | /* Virtual function table for the BindCtx class. */
|
|---|
| 86 | static ICOM_VTABLE(IBindCtx) VT_BindCtxImpl =
|
|---|
| 87 | {
|
|---|
| 88 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 89 | BindCtxImpl_QueryInterface,
|
|---|
| 90 | BindCtxImpl_AddRef,
|
|---|
| 91 | BindCtxImpl_Release,
|
|---|
| 92 | BindCtxImpl_RegisterObjectBound,
|
|---|
| 93 | BindCtxImpl_RevokeObjectBound,
|
|---|
| 94 | BindCtxImpl_ReleaseBoundObjects,
|
|---|
| 95 | BindCtxImpl_SetBindOptions,
|
|---|
| 96 | BindCtxImpl_GetBindOptions,
|
|---|
| 97 | BindCtxImpl_GetRunningObjectTable,
|
|---|
| 98 | BindCtxImpl_RegisterObjectParam,
|
|---|
| 99 | BindCtxImpl_GetObjectParam,
|
|---|
| 100 | BindCtxImpl_EnumObjectParam,
|
|---|
| 101 | BindCtxImpl_RevokeObjectParam
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 104 | /*******************************************************************************
|
|---|
| 105 | * BindCtx_QueryInterface
|
|---|
| 106 | *******************************************************************************/
|
|---|
| 107 | HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject)
|
|---|
| 108 | {
|
|---|
| 109 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 110 |
|
|---|
| 111 | TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
|
|---|
| 112 |
|
|---|
| 113 | /* Perform a sanity check on the parameters.*/
|
|---|
| 114 | if ( (This==0) || (ppvObject==0) )
|
|---|
| 115 | return E_INVALIDARG;
|
|---|
| 116 |
|
|---|
| 117 | /* Initialize the return parameter.*/
|
|---|
| 118 | *ppvObject = 0;
|
|---|
| 119 |
|
|---|
| 120 | /* Compare the riid with the interface IDs implemented by this object.*/
|
|---|
| 121 | if (IsEqualIID(&IID_IUnknown, riid))
|
|---|
| 122 | *ppvObject = (IBindCtx*)This;
|
|---|
| 123 | else
|
|---|
| 124 | if (IsEqualIID(&IID_IBindCtx, riid))
|
|---|
| 125 | *ppvObject = (IBindCtx*)This;
|
|---|
| 126 |
|
|---|
| 127 | /* Check that we obtained an interface.*/
|
|---|
| 128 | if ((*ppvObject)==0)
|
|---|
| 129 | return E_NOINTERFACE;
|
|---|
| 130 |
|
|---|
| 131 | /* Query Interface always increases the reference count by one when it is successful */
|
|---|
| 132 | BindCtxImpl_AddRef(iface);
|
|---|
| 133 |
|
|---|
| 134 | return S_OK;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /******************************************************************************
|
|---|
| 138 | * BindCtx_AddRef
|
|---|
| 139 | ******************************************************************************/
|
|---|
| 140 | ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface)
|
|---|
| 141 | {
|
|---|
| 142 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 143 |
|
|---|
| 144 | TRACE("(%p)\n",This);
|
|---|
| 145 |
|
|---|
| 146 | return ++(This->ref);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | /******************************************************************************
|
|---|
| 150 | * BindCtx_Release
|
|---|
| 151 | ******************************************************************************/
|
|---|
| 152 | ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface)
|
|---|
| 153 | {
|
|---|
| 154 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 155 |
|
|---|
| 156 | TRACE("(%p)\n",This);
|
|---|
| 157 |
|
|---|
| 158 | This->ref--;
|
|---|
| 159 |
|
|---|
| 160 | if (This->ref==0){
|
|---|
| 161 |
|
|---|
| 162 | /* release all registered objects */
|
|---|
| 163 | BindCtxImpl_ReleaseBoundObjects((IBindCtx*)This);
|
|---|
| 164 |
|
|---|
| 165 | BindCtxImpl_Destroy(This);
|
|---|
| 166 |
|
|---|
| 167 | return 0;
|
|---|
| 168 | }
|
|---|
| 169 | return This->ref;;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 | /******************************************************************************
|
|---|
| 174 | * BindCtx_Construct (local function)
|
|---|
| 175 | *******************************************************************************/
|
|---|
| 176 | HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This)
|
|---|
| 177 | {
|
|---|
| 178 | TRACE("(%p)\n",This);
|
|---|
| 179 |
|
|---|
| 180 | /* Initialize the virtual function table.*/
|
|---|
| 181 | ICOM_VTBL(This) = &VT_BindCtxImpl;
|
|---|
| 182 | This->ref = 0;
|
|---|
| 183 |
|
|---|
| 184 | /* Initialize the BIND_OPTS2 structure */
|
|---|
| 185 | This->bindOption2.cbStruct = sizeof(BIND_OPTS2);
|
|---|
| 186 | This->bindOption2.grfFlags = 0;
|
|---|
| 187 | This->bindOption2.grfMode = STGM_READWRITE;
|
|---|
| 188 | This->bindOption2.dwTickCountDeadline = 0;
|
|---|
| 189 |
|
|---|
| 190 | This->bindOption2.dwTrackFlags = 0;
|
|---|
| 191 | This->bindOption2.dwClassContext = CLSCTX_SERVER;
|
|---|
| 192 | This->bindOption2.locale = 1033;
|
|---|
| 193 | This->bindOption2.pServerInfo = 0;
|
|---|
| 194 |
|
|---|
| 195 | /* Initialize the bindctx table */
|
|---|
| 196 | This->bindCtxTableSize=BLOCK_TAB_SIZE;
|
|---|
| 197 | This->bindCtxTableLastIndex=0;
|
|---|
| 198 | This->bindCtxTable= HeapAlloc(GetProcessHeap(), 0,This->bindCtxTableSize*sizeof(BindCtxObject));
|
|---|
| 199 |
|
|---|
| 200 | if (This->bindCtxTable==NULL)
|
|---|
| 201 | return E_OUTOFMEMORY;
|
|---|
| 202 |
|
|---|
| 203 | return S_OK;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | /******************************************************************************
|
|---|
| 207 | * BindCtx_Destroy (local function)
|
|---|
| 208 | *******************************************************************************/
|
|---|
| 209 | HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This)
|
|---|
| 210 | {
|
|---|
| 211 | TRACE("(%p)\n",This);
|
|---|
| 212 |
|
|---|
| 213 | /* free the table space memory */
|
|---|
| 214 | HeapFree(GetProcessHeap(),0,This->bindCtxTable);
|
|---|
| 215 |
|
|---|
| 216 | /* free the bindctx structure */
|
|---|
| 217 | HeapFree(GetProcessHeap(),0,This);
|
|---|
| 218 |
|
|---|
| 219 | return S_OK;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | /******************************************************************************
|
|---|
| 224 | * BindCtx_RegisterObjectBound
|
|---|
| 225 | ******************************************************************************/
|
|---|
| 226 | HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk)
|
|---|
| 227 | {
|
|---|
| 228 |
|
|---|
| 229 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 230 | DWORD lastIndex=This->bindCtxTableLastIndex;
|
|---|
| 231 | BindCtxObject cell;
|
|---|
| 232 |
|
|---|
| 233 | TRACE("(%p,%p)\n",This,punk);
|
|---|
| 234 |
|
|---|
| 235 | if (punk==NULL)
|
|---|
| 236 | return E_POINTER;
|
|---|
| 237 |
|
|---|
| 238 | IUnknown_AddRef(punk);
|
|---|
| 239 |
|
|---|
| 240 | /* put the object in the first free element in the table */
|
|---|
| 241 | This->bindCtxTable[lastIndex].pObj = punk;
|
|---|
| 242 | This->bindCtxTable[lastIndex].pkeyObj = NULL;
|
|---|
| 243 | This->bindCtxTable[lastIndex].regType = 0;
|
|---|
| 244 | cell=This->bindCtxTable[lastIndex];
|
|---|
| 245 | lastIndex= ++This->bindCtxTableLastIndex;
|
|---|
| 246 |
|
|---|
| 247 | if (lastIndex == This->bindCtxTableSize){ /* the table is full so it must be resized */
|
|---|
| 248 |
|
|---|
| 249 | if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE)){
|
|---|
| 250 | FIXME("This->bindCtxTableSize: %ld is out of data limite \n",This->bindCtxTableSize);
|
|---|
| 251 | return E_FAIL;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */
|
|---|
| 255 |
|
|---|
| 256 | This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable,
|
|---|
| 257 | This->bindCtxTableSize * sizeof(BindCtxObject));
|
|---|
| 258 | if (!This->bindCtxTable)
|
|---|
| 259 | return E_OUTOFMEMORY;
|
|---|
| 260 | }
|
|---|
| 261 | return S_OK;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | /******************************************************************************
|
|---|
| 265 | * BindCtx_RevokeObjectBound
|
|---|
| 266 | ******************************************************************************/
|
|---|
| 267 | HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk)
|
|---|
| 268 | {
|
|---|
| 269 | DWORD index,j;
|
|---|
| 270 |
|
|---|
| 271 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 272 |
|
|---|
| 273 | TRACE("(%p,%p)\n",This,punk);
|
|---|
| 274 |
|
|---|
| 275 | /* check if the object was registred or not */
|
|---|
| 276 | if (BindCtxImpl_GetObjectIndex(This,punk,NULL,&index)==S_FALSE)
|
|---|
| 277 |
|
|---|
| 278 | return MK_E_NOTBOUND;
|
|---|
| 279 |
|
|---|
| 280 | IUnknown_Release(This->bindCtxTable[index].pObj);
|
|---|
| 281 |
|
|---|
| 282 | /* left-shift all elements in the right side of the current revoked object */
|
|---|
| 283 | for(j=index; j<This->bindCtxTableLastIndex-1; j++)
|
|---|
| 284 | This->bindCtxTable[j]= This->bindCtxTable[j+1];
|
|---|
| 285 |
|
|---|
| 286 | This->bindCtxTableLastIndex--;
|
|---|
| 287 |
|
|---|
| 288 | return S_OK;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | /******************************************************************************
|
|---|
| 292 | * BindCtx_ReleaseBoundObjects
|
|---|
| 293 | ******************************************************************************/
|
|---|
| 294 | HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface)
|
|---|
| 295 | {
|
|---|
| 296 | DWORD i;
|
|---|
| 297 |
|
|---|
| 298 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 299 |
|
|---|
| 300 | TRACE("(%p)\n",This);
|
|---|
| 301 |
|
|---|
| 302 | for(i=0;i<This->bindCtxTableLastIndex;i++)
|
|---|
| 303 | IUnknown_Release(This->bindCtxTable[i].pObj);
|
|---|
| 304 |
|
|---|
| 305 | This->bindCtxTableLastIndex = 0;
|
|---|
| 306 |
|
|---|
| 307 | return S_OK;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | /******************************************************************************
|
|---|
| 311 | * BindCtx_SetBindOptions
|
|---|
| 312 | ******************************************************************************/
|
|---|
| 313 | HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts)
|
|---|
| 314 | {
|
|---|
| 315 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 316 |
|
|---|
| 317 | TRACE("(%p,%p)\n",This,pbindopts);
|
|---|
| 318 |
|
|---|
| 319 | if (pbindopts==NULL)
|
|---|
| 320 | return E_POINTER;
|
|---|
| 321 |
|
|---|
| 322 | if (pbindopts->cbStruct > sizeof(BIND_OPTS2))
|
|---|
| 323 | {
|
|---|
| 324 | WARN("invalid size");
|
|---|
| 325 | return E_INVALIDARG; /* FIXME : not verified */
|
|---|
| 326 | }
|
|---|
| 327 | memcpy(&This->bindOption2, pbindopts, pbindopts->cbStruct);
|
|---|
| 328 | return S_OK;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | /******************************************************************************
|
|---|
| 332 | * BindCtx_GetBindOptions
|
|---|
| 333 | ******************************************************************************/
|
|---|
| 334 | HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts)
|
|---|
| 335 | {
|
|---|
| 336 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 337 |
|
|---|
| 338 | TRACE("(%p,%p)\n",This,pbindopts);
|
|---|
| 339 |
|
|---|
| 340 | if (pbindopts==NULL)
|
|---|
| 341 | return E_POINTER;
|
|---|
| 342 |
|
|---|
| 343 | if (pbindopts->cbStruct > sizeof(BIND_OPTS2))
|
|---|
| 344 | {
|
|---|
| 345 | WARN("invalid size");
|
|---|
| 346 | return E_INVALIDARG; /* FIXME : not verified */
|
|---|
| 347 | }
|
|---|
| 348 | memcpy(pbindopts, &This->bindOption2, pbindopts->cbStruct);
|
|---|
| 349 | return S_OK;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | /******************************************************************************
|
|---|
| 353 | * BindCtx_GetRunningObjectTable
|
|---|
| 354 | ******************************************************************************/
|
|---|
| 355 | HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot)
|
|---|
| 356 | {
|
|---|
| 357 | HRESULT res;
|
|---|
| 358 |
|
|---|
| 359 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 360 |
|
|---|
| 361 | TRACE("(%p,%p)\n",This,pprot);
|
|---|
| 362 |
|
|---|
| 363 | if (pprot==NULL)
|
|---|
| 364 | return E_POINTER;
|
|---|
| 365 |
|
|---|
| 366 | res=GetRunningObjectTable(0, pprot);
|
|---|
| 367 |
|
|---|
| 368 | return res;
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | /******************************************************************************
|
|---|
| 372 | * BindCtx_RegisterObjectParam
|
|---|
| 373 | ******************************************************************************/
|
|---|
| 374 | HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk)
|
|---|
| 375 | {
|
|---|
| 376 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 377 |
|
|---|
| 378 | TRACE("(%p,%p,%p)\n",This,pszkey,punk);
|
|---|
| 379 |
|
|---|
| 380 | if (punk==NULL)
|
|---|
| 381 | return E_INVALIDARG;
|
|---|
| 382 |
|
|---|
| 383 | IUnknown_AddRef(punk);
|
|---|
| 384 |
|
|---|
| 385 | This->bindCtxTable[This->bindCtxTableLastIndex].pObj = punk;
|
|---|
| 386 | This->bindCtxTable[This->bindCtxTableLastIndex].regType = 1;
|
|---|
| 387 |
|
|---|
| 388 | if (pszkey==NULL)
|
|---|
| 389 |
|
|---|
| 390 | This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=NULL;
|
|---|
| 391 |
|
|---|
| 392 | else{
|
|---|
| 393 |
|
|---|
| 394 | This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=
|
|---|
| 395 | HeapAlloc(GetProcessHeap(),0,(sizeof(WCHAR)*(1+lstrlenW(pszkey))));
|
|---|
| 396 |
|
|---|
| 397 | if (This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj==NULL)
|
|---|
| 398 | return E_OUTOFMEMORY;
|
|---|
| 399 | strcpyW(This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj,pszkey);
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | This->bindCtxTableLastIndex++;
|
|---|
| 403 |
|
|---|
| 404 | if (This->bindCtxTableLastIndex == This->bindCtxTableSize){ /* table is full ! must be resized */
|
|---|
| 405 |
|
|---|
| 406 | This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */
|
|---|
| 407 |
|
|---|
| 408 | if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE)){
|
|---|
| 409 | FIXME("This->bindCtxTableSize: %ld is out of data limite \n",This->bindCtxTableSize);
|
|---|
| 410 | return E_FAIL;
|
|---|
| 411 | }
|
|---|
| 412 | This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable,
|
|---|
| 413 | This->bindCtxTableSize * sizeof(BindCtxObject));
|
|---|
| 414 | if (!This->bindCtxTable)
|
|---|
| 415 | return E_OUTOFMEMORY;
|
|---|
| 416 | }
|
|---|
| 417 | return S_OK;
|
|---|
| 418 | }
|
|---|
| 419 | /******************************************************************************
|
|---|
| 420 | * BindCtx_GetObjectParam
|
|---|
| 421 | ******************************************************************************/
|
|---|
| 422 | HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk)
|
|---|
| 423 | {
|
|---|
| 424 | DWORD index;
|
|---|
| 425 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 426 |
|
|---|
| 427 | TRACE("(%p,%p,%p)\n",This,pszkey,punk);
|
|---|
| 428 |
|
|---|
| 429 | if (punk==NULL)
|
|---|
| 430 | return E_POINTER;
|
|---|
| 431 |
|
|---|
| 432 | *punk=0;
|
|---|
| 433 |
|
|---|
| 434 | if (BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_FALSE)
|
|---|
| 435 | return E_FAIL;
|
|---|
| 436 |
|
|---|
| 437 | IUnknown_AddRef(This->bindCtxTable[index].pObj);
|
|---|
| 438 |
|
|---|
| 439 | *punk = This->bindCtxTable[index].pObj;
|
|---|
| 440 |
|
|---|
| 441 | return S_OK;
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | /******************************************************************************
|
|---|
| 445 | * BindCtx_RevokeObjectParam
|
|---|
| 446 | ******************************************************************************/
|
|---|
| 447 | HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR ppenum)
|
|---|
| 448 | {
|
|---|
| 449 | DWORD index,j;
|
|---|
| 450 |
|
|---|
| 451 | ICOM_THIS(BindCtxImpl,iface);
|
|---|
| 452 |
|
|---|
| 453 | TRACE("(%p,%p)\n",This,ppenum);
|
|---|
| 454 |
|
|---|
| 455 | if (BindCtxImpl_GetObjectIndex(This,NULL,ppenum,&index)==S_FALSE)
|
|---|
| 456 | return E_FAIL;
|
|---|
| 457 |
|
|---|
| 458 | /* release the object if it's found */
|
|---|
| 459 | IUnknown_Release(This->bindCtxTable[index].pObj);
|
|---|
| 460 |
|
|---|
| 461 | /* remove the object from the table with a left-shifting of all objects in the right side */
|
|---|
| 462 | for(j=index; j<This->bindCtxTableLastIndex-1; j++)
|
|---|
| 463 | This->bindCtxTable[j]= This->bindCtxTable[j+1];
|
|---|
| 464 |
|
|---|
| 465 | This->bindCtxTableLastIndex--;
|
|---|
| 466 |
|
|---|
| 467 | return S_OK;
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | /******************************************************************************
|
|---|
| 471 | * BindCtx_EnumObjectParam
|
|---|
| 472 | ******************************************************************************/
|
|---|
| 473 | HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** pszkey)
|
|---|
| 474 | {
|
|---|
| 475 | FIXME("(%p,%p),stub!\n",iface,pszkey);
|
|---|
| 476 | return E_NOTIMPL;
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | /********************************************************************************
|
|---|
| 480 | * GetObjectIndex (local function)
|
|---|
| 481 | ********************************************************************************/
|
|---|
| 482 | HRESULT WINAPI BindCtxImpl_GetObjectIndex(BindCtxImpl* This,
|
|---|
| 483 | IUnknown* punk,
|
|---|
| 484 | LPOLESTR pszkey,
|
|---|
| 485 | DWORD *index)
|
|---|
| 486 | {
|
|---|
| 487 |
|
|---|
| 488 | DWORD i;
|
|---|
| 489 | BYTE found=0;
|
|---|
| 490 |
|
|---|
| 491 | TRACE("(%p,%p,%p,%p)\n",This,punk,pszkey,index);
|
|---|
| 492 |
|
|---|
| 493 | if (punk==NULL)
|
|---|
| 494 | /* search object identified by a register key */
|
|---|
| 495 | for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++){
|
|---|
| 496 |
|
|---|
| 497 | if(This->bindCtxTable[i].regType==1){
|
|---|
| 498 |
|
|---|
| 499 | if ( ( (This->bindCtxTable[i].pkeyObj==NULL) && (pszkey==NULL) ) ||
|
|---|
| 500 | ( (This->bindCtxTable[i].pkeyObj!=NULL) &&
|
|---|
| 501 | (pszkey!=NULL) &&
|
|---|
| 502 | (lstrcmpW(This->bindCtxTable[i].pkeyObj,pszkey)==0)
|
|---|
| 503 | )
|
|---|
| 504 | )
|
|---|
| 505 |
|
|---|
| 506 | found=1;
|
|---|
| 507 | }
|
|---|
| 508 | }
|
|---|
| 509 | else
|
|---|
| 510 | /* search object identified by a moniker*/
|
|---|
| 511 | for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++)
|
|---|
| 512 | if(This->bindCtxTable[i].pObj==punk)
|
|---|
| 513 | found=1;
|
|---|
| 514 |
|
|---|
| 515 | if (index != NULL)
|
|---|
| 516 | *index=i-1;
|
|---|
| 517 |
|
|---|
| 518 | if (found)
|
|---|
| 519 | return S_OK;
|
|---|
| 520 | else
|
|---|
| 521 | return S_FALSE;
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | /******************************************************************************
|
|---|
| 525 | * CreateBindCtx16
|
|---|
| 526 | ******************************************************************************/
|
|---|
| 527 | HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc)
|
|---|
| 528 | {
|
|---|
| 529 | FIXME("(%ld,%p),stub!\n",reserved,ppbc);
|
|---|
| 530 | return E_NOTIMPL;
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | /******************************************************************************
|
|---|
| 534 | * CreateBindCtx
|
|---|
| 535 | ******************************************************************************/
|
|---|
| 536 | HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC * ppbc)
|
|---|
| 537 | {
|
|---|
| 538 | BindCtxImpl* newBindCtx = 0;
|
|---|
| 539 | HRESULT hr;
|
|---|
| 540 | IID riid=IID_IBindCtx;
|
|---|
| 541 |
|
|---|
| 542 | TRACE("(%ld,%p)\n",reserved,ppbc);
|
|---|
| 543 |
|
|---|
| 544 | newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl));
|
|---|
| 545 |
|
|---|
| 546 | if (newBindCtx == 0)
|
|---|
| 547 | return E_OUTOFMEMORY;
|
|---|
| 548 |
|
|---|
| 549 | hr = BindCtxImpl_Construct(newBindCtx);
|
|---|
| 550 |
|
|---|
| 551 | if (FAILED(hr)){
|
|---|
| 552 |
|
|---|
| 553 | HeapFree(GetProcessHeap(),0,newBindCtx);
|
|---|
| 554 | return hr;
|
|---|
| 555 | }
|
|---|
| 556 |
|
|---|
| 557 | hr = BindCtxImpl_QueryInterface((IBindCtx*)newBindCtx,&riid,(void**)ppbc);
|
|---|
| 558 |
|
|---|
| 559 | return hr;
|
|---|
| 560 | }
|
|---|