bindctx.c 9.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
/***************************************************************************************
 *	                      BindCtx implementation
 *
 *  Copyright 1999  Noomen Hamza
 ***************************************************************************************/

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "winerror.h"
#include "wine/obj_base.h"
#include "wine/obj_storage.h"
#include "wine/obj_moniker.h"
#include "debug.h"
#include "heap.h"

typedef struct BindCtxImpl{

    ICOM_VTABLE(IBindCtx)*  lpvtbl;   
                                     
    ULONG ref;

} BindCtxImpl;


HRESULT WINAPI BindCtxImpl_QueryInterface(BindCtxImpl* This,REFIID riid,void** ppvObject);
ULONG   WINAPI BindCtxImpl_AddRef(BindCtxImpl* This);
ULONG   WINAPI BindCtxImpl_Release(BindCtxImpl* This);
HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This);
HRESULT WINAPI BindCtxImpl_destroy(BindCtxImpl* This);
HRESULT WINAPI BindCtxImpl_RegisterObjectBound(BindCtxImpl* This,IUnknown* punk);
HRESULT WINAPI BindCtxImpl_RevokeObjectBound(BindCtxImpl* This, IUnknown* punk);
HRESULT WINAPI BindCtxImpl_ReleaseObjects(BindCtxImpl* This);
HRESULT WINAPI BindCtxImpl_SetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts);
HRESULT WINAPI BindCtxImpl_GetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts);
HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(BindCtxImpl* This,IRunningObjectTable** pprot);
HRESULT WINAPI BindCtxImpl_RegisterObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk);
HRESULT WINAPI BindCtxImpl_GetObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk);
HRESULT WINAPI BindCtxImpl_EnumObjectParam(BindCtxImpl* This,IEnumString** ppenum);
HRESULT WINAPI BindCtxImpl_RevokeObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey);
HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc);
HRESULT WINAPI CreateBindCtx32(DWORD reserved, LPBC * ppbc);

#define VTABLE_FUNC(a) (void*)(a)
// Virtual function table for the BindCtx class.
static ICOM_VTABLE(IBindCtx) VT_BindCtxImpl =
{
    {
      VTABLE_FUNC(BindCtxImpl_QueryInterface),
      VTABLE_FUNC(BindCtxImpl_AddRef),
      VTABLE_FUNC(BindCtxImpl_Release)
    },
    VTABLE_FUNC(BindCtxImpl_RegisterObjectBound),
    VTABLE_FUNC(BindCtxImpl_RevokeObjectBound),
    VTABLE_FUNC(BindCtxImpl_ReleaseObjects),
    VTABLE_FUNC(BindCtxImpl_SetBindOptions),
    VTABLE_FUNC(BindCtxImpl_GetBindOptions),
    VTABLE_FUNC(BindCtxImpl_GetRunningObjectTable),
    VTABLE_FUNC(BindCtxImpl_RegisterObjectParam),
    VTABLE_FUNC(BindCtxImpl_GetObjectParam),
    VTABLE_FUNC(BindCtxImpl_EnumObjectParam),
    VTABLE_FUNC(BindCtxImpl_RevokeObjectParam)
};

/*******************************************************************************
 *        BindCtx_QueryInterface
 *******************************************************************************/
HRESULT WINAPI BindCtxImpl_QueryInterface(BindCtxImpl* This,REFIID riid,void** ppvObject){

  TRACE(ole,"(%p,%p,%p)\n",This,riid,ppvObject);
  // Perform a sanity check on the parameters.
  if ( (This==0) || (ppvObject==0) )    return E_INVALIDARG;
  
  // Initialize the return parameter.
  *ppvObject = 0;

  // Compare the riid with the interface IDs implemented by this object.
  if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
      *ppvObject = (IBindCtx*)This;
  else
      if (memcmp(&IID_IBindCtx, riid, sizeof(IID_IBindCtx)) == 0)
          *ppvObject = (IBindCtx*)This;

  // Check that we obtained an interface.
  if ((*ppvObject)==0)        return E_NOINTERFACE;
  
   // Query Interface always increases the reference count by one when it is successful
  BindCtxImpl_AddRef(This);

  return S_OK;
}

/******************************************************************************
 *       BindCtx_ _AddRef
 ******************************************************************************/
ULONG WINAPI BindCtxImpl_AddRef(BindCtxImpl* This){

    TRACE(ole,"(%p)\n",This);

    return ++(This->ref);
}

/******************************************************************************
 *        BindCtx_Release
 ******************************************************************************/
ULONG WINAPI BindCtxImpl_Release(BindCtxImpl* This){

    TRACE(ole,"(%p)\n",This);

    This->ref--;

    if (This->ref==0){
        BindCtxImpl_destroy(This);
        return 0;
    }
    return This->ref;;
}


/******************************************************************************
 *         BindCtx_Constructor
 *******************************************************************************/
HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This){

    FIXME(ole,"(%p),stub!\n",This);

    memset(This, 0, sizeof(BindCtxImpl));

    //Initialize the virtual fgunction table.
    This->lpvtbl       = &VT_BindCtxImpl;

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_destructor
 *******************************************************************************/
HRESULT WINAPI BindCtxImpl_destroy(BindCtxImpl* This){

    FIXME(ole,"(%p),stub!\n",This);

    SEGPTR_FREE(This);

    return S_OK;
}


/******************************************************************************
 *        BindCtx_RegisterObjectBound
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_RegisterObjectBound(BindCtxImpl* This,IUnknown* punk){

    FIXME(ole,"(%p,%p),stub!\n",This,punk);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_RevokeObjectBound
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_RevokeObjectBound(BindCtxImpl* This, IUnknown* punk){

    FIXME(ole,"(%p,%p),stub!\n",This,punk);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_ReleaseObjects
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_ReleaseObjects(BindCtxImpl* This){

    FIXME(ole,"(%p),stub!\n",This);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_SetBindOptions
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_SetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts){

    FIXME(ole,"(%p,%p),stub!\n",This,pbindopts);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_GetBindOptions
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_GetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts){

    FIXME(ole,"(%p,%p),stub!\n",This,pbindopts);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_GetRunningObjectTable
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(BindCtxImpl* This,IRunningObjectTable** pprot){

    FIXME(ole,"(%p,%p),stub!\n",This,pprot);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_RegisterObjectParam
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_RegisterObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk){

    FIXME(ole,"(%p,%p,%p),stub!\n",This,pszkey,punk);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_GetObjectParam
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_GetObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk){

    FIXME(ole,"(%p,%p,%p),stub!\n",This,pszkey,punk);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_EnumObjectParam
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_EnumObjectParam(BindCtxImpl* This,IEnumString** ppenum){

    FIXME(ole,"(%p,%p),stub!\n",This,ppenum);

    return E_NOTIMPL;
}

/******************************************************************************
 *        BindCtx_RevokeObjectParam
 ******************************************************************************/
HRESULT WINAPI BindCtxImpl_RevokeObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey){

    FIXME(ole,"(%p,%p),stub!\n",This,pszkey);

    return E_NOTIMPL;
}


/******************************************************************************
 *        CreateBindCtx16
 ******************************************************************************/
HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc){

    FIXME(ole,"(%ld,%p),stub!\n",reserved,ppbc);

    return E_NOTIMPL;
}

/******************************************************************************
 *        CreateBindCtx32
 ******************************************************************************/
HRESULT WINAPI CreateBindCtx32(DWORD reserved, LPBC * ppbc){

    BindCtxImpl* newBindCtx = 0;
    HRESULT        hr = S_OK;

    TRACE(ole,"(%ld,%p)\n",reserved,ppbc);

    newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl));

    if (newBindCtx == 0)
        return STG_E_INSUFFICIENTMEMORY;

    hr = BindCtxImpl_Construct(newBindCtx);

    if (FAILED(hr))
        return hr;

    hr = BindCtxImpl_QueryInterface(newBindCtx,&IID_IBindCtx,(void**)ppbc);

    return hr;
}