From e0849c8a528bbb77b9802c58f815c4bbd97f4486 Mon Sep 17 00:00:00 2001
From: James Hatheway <james@macadamian.com>
Date: Fri, 1 Sep 2000 01:21:08 +0000
Subject: [PATCH] Implemented CoGetPSClsid().

---
 dlls/ole32/compobj.c  | 69 +++++++++++++++++++++++++++++++++++++++++++
 dlls/ole32/ole32.spec |  2 +-
 2 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c
index f6514f3f300..f25953bce27 100644
--- a/dlls/ole32/compobj.c
+++ b/dlls/ole32/compobj.c
@@ -756,6 +756,75 @@ HRESULT WINAPI CLSIDFromProgID(
 	return ret;
 }
 
+
+
+/*****************************************************************************
+ *             CoGetPSClsid [OLE32.22]
+ *
+ * This function returns the CLSID of the DLL that implements the proxy and stub
+ * for the specified interface. 
+ *
+ * It determines this by searching the 
+ * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
+ * and any interface id registered by CoRegisterPSClsid within the current process.
+ * 
+ * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
+ */
+HRESULT WINAPI CoGetPSClsid(
+          REFIID riid,     /* [in]  Interface whose proxy/stub CLSID is to be returned */
+          CLSID *pclsid )    /* [out] Where to store returned proxy/stub CLSID */
+{
+    char *buf, buf2[40];
+    DWORD buf2len;
+    HKEY xhkey;
+
+    TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
+
+    /* Get the input iid as a string */
+    WINE_StringFromCLSID(riid, buf2);
+    /* Allocate memory for the registry key we will construct.
+       (length of iid string plus constant length of static text */
+    buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
+    if (buf == NULL)
+    {
+       return (E_OUTOFMEMORY);
+    }
+
+    /* Construct the registry key we want */
+    sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
+
+    /* Open the key.. */
+    if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
+    {
+       HeapFree(GetProcessHeap(),0,buf);
+       return (E_INVALIDARG);
+    }
+    HeapFree(GetProcessHeap(),0,buf);
+
+    /* ... Once we have the key, query the registry to get the
+       value of CLSID as a string, and convert it into a 
+       proper CLSID structure to be passed back to the app */
+    buf2len = sizeof(buf2);
+    if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
+    {
+       RegCloseKey(xhkey);
+       return E_INVALIDARG;
+    }
+    RegCloseKey(xhkey);
+
+    /* We have the CLSid we want back from the registry as a string, so
+       lets convert it into a CLSID structure */
+    if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
+    {
+       return E_INVALIDARG;
+    }
+
+    TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
+    return (S_OK);
+}
+
+
+
 /***********************************************************************
  *		WriteClassStm
  *
diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec
index 724e3d5d881..8b02386f5e5 100644
--- a/dlls/ole32/ole32.spec
+++ b/dlls/ole32/ole32.spec
@@ -28,7 +28,7 @@ import kernel32.dll
  19 stub CoGetInterfaceAndReleaseStream # stdcall (ptr ptr ptr) return 0,ERR_NOTIMPLEMENTED
  20 stdcall CoGetMalloc(long ptr) CoGetMalloc
  21 stub CoGetMarshalSizeMax        # stdcall (ptr ptr ptr long ptr long) return 0,ERR_NOTIMPLEMENTED
- 22 stub CoGetPSClsid               # stdcall (ptr ptr) return 0,ERR_NOTIMPLEMENTED
+ 22 stdcall CoGetPSClsid(ptr ptr) CoGetPSClsid 
  23 stub CoGetStandardMarshal       # stdcall (ptr ptr long ptr long ptr) return 0,ERR_NOTIMPLEMENTED
  24 stub CoGetState
  25 stub CoGetTreatAsClass          # stdcall (ptr ptr) return 0,ERR_NOTIMPLEMENTED
-- 
GitLab