Make the ClassFactory proxy support aggregation.

diff --git a/dlls/ole32/oleproxy.c b/dlls/ole32/oleproxy.c
index b9f6534..5255474 100644
--- a/dlls/ole32/oleproxy.c
+++ b/dlls/ole32/oleproxy.c
@@ -270,6 +270,7 @@
     DWORD				ref;
 
     IRpcChannelBuffer			*chanbuf;
+    IUnknown *outer_unknown;
 } CFProxy;
 
 static HRESULT WINAPI IRpcProxyBufferImpl_QueryInterface(LPRPCPROXYBUFFER iface,REFIID riid,LPVOID *ppv) {
@@ -316,6 +317,8 @@
 
 static HRESULT WINAPI
 CFProxy_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppv) {
+    ICOM_THIS_MULTI(CFProxy,lpvtbl_proxy,iface);
+    if (This->outer_unknown) return IUnknown_QueryInterface(This->outer_unknown, riid, ppv);
     *ppv = NULL;
     if (IsEqualIID(&IID_IClassFactory,riid) || IsEqualIID(&IID_IUnknown,riid)) {
 	*ppv = (LPVOID)iface;
@@ -330,15 +333,22 @@
 
 static ULONG   WINAPI CFProxy_AddRef(LPCLASSFACTORY iface) {
     ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
+    if (This->outer_unknown) return IUnknown_AddRef(This->outer_unknown);
     return InterlockedIncrement(&This->ref);
 }
 
 static ULONG   WINAPI CFProxy_Release(LPCLASSFACTORY iface) {
     ULONG ref;
     ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface);
-    
-    ref = InterlockedDecrement(&This->ref);
-    if (!ref) HeapFree(GetProcessHeap(),0,This);
+    if (This->outer_unknown)
+        ref = IUnknown_Release(This->outer_unknown);
+    else    
+        ref = InterlockedDecrement(&This->ref);
+
+    if (!ref) {
+      	IRpcChannelBuffer_Release(This->chanbuf);
+        HeapFree(GetProcessHeap(),0,This);
+    }
     return ref;
 }
 
@@ -424,7 +434,7 @@
 };
 
 static HRESULT
-CFProxy_Construct(LPVOID *ppv,LPVOID *ppProxy) {
+CFProxy_Construct(IUnknown *pUnkOuter, LPVOID *ppv,LPVOID *ppProxy) {
     CFProxy *cf;
 
     cf = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CFProxy));
@@ -433,10 +443,13 @@
 
     cf->lpvtbl_cf	= &cfproxyvt;
     cf->lpvtbl_proxy	= &pspbvtbl;
-    /* 1 reference for the proxy and 1 for the object */
-    cf->ref		= 2;
+    /* 1 reference for the proxy... */
+    cf->ref		= 1;
+    cf->outer_unknown = pUnkOuter;
     *ppv		= &(cf->lpvtbl_cf);
     *ppProxy		= &(cf->lpvtbl_proxy);
+    /* ...and 1 for the object */
+    IUnknown_AddRef((IUnknown *)*ppv);
     return S_OK;
 }
 
@@ -464,7 +477,7 @@
     if (IsEqualIID(&IID_IClassFactory,riid) ||
 	IsEqualIID(&IID_IUnknown,riid)
     )
-	return CFProxy_Construct(ppv,(LPVOID*)ppProxy);
+	return CFProxy_Construct(pUnkOuter, ppv,(LPVOID*)ppProxy);
     FIXME("proxying not implemented for (%s) yet!\n",debugstr_guid(riid));
     return E_FAIL;
 }