4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2002 Marcus Meissner
6 * Copyright 2005 Mike Hearn, Rob Shearman for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
45 #include "wine/unicode.h"
47 #include "compobj_private.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ole);
53 static void __RPC_STUB dispatch_rpc(RPC_MESSAGE *msg);
55 /* we only use one function to dispatch calls for all methods - we use the
56 * RPC_IF_OLE flag to tell the RPC runtime that this is the case */
57 static RPC_DISPATCH_FUNCTION rpc_dispatch_table[1] = { dispatch_rpc }; /* (RO) */
58 static RPC_DISPATCH_TABLE rpc_dispatch = { 1, rpc_dispatch_table }; /* (RO) */
60 static struct list registered_interfaces = LIST_INIT(registered_interfaces); /* (CS csRegIf) */
61 static CRITICAL_SECTION csRegIf;
62 static CRITICAL_SECTION_DEBUG csRegIf_debug =
65 { &csRegIf_debug.ProcessLocksList, &csRegIf_debug.ProcessLocksList },
66 0, 0, { 0, (DWORD)(__FILE__ ": dcom registered server interfaces") }
68 static CRITICAL_SECTION csRegIf = { &csRegIf_debug, -1, 0, 0, 0, 0 };
70 static WCHAR wszPipeTransport[] = {'n','c','a','c','n','_','n','p',0};
76 DWORD refs; /* ref count */
77 RPC_SERVER_INTERFACE If; /* interface registered with the RPC runtime */
80 /* get the pipe endpoint specified of the specified apartment */
81 static inline void get_rpc_endpoint(LPWSTR endpoint, const OXID *oxid)
83 /* FIXME: should get endpoint from rpcss */
84 static const WCHAR wszEndpointFormat[] = {'\\','p','i','p','e','\\','O','L','E','_','%','0','8','l','x','%','0','8','l','x',0};
85 wsprintfW(endpoint, wszEndpointFormat, (DWORD)(*oxid >> 32),(DWORD)*oxid);
90 const IRpcChannelBufferVtbl *lpVtbl;
96 RpcChannelBuffer super; /* superclass */
98 RPC_BINDING_HANDLE bind; /* handle to the remote server */
99 } ClientRpcChannelBuffer;
101 static HRESULT WINAPI RpcChannelBuffer_QueryInterface(LPRPCCHANNELBUFFER iface, REFIID riid, LPVOID *ppv)
104 if (IsEqualIID(riid,&IID_IRpcChannelBuffer) || IsEqualIID(riid,&IID_IUnknown))
106 *ppv = (LPVOID)iface;
107 IUnknown_AddRef(iface);
110 return E_NOINTERFACE;
113 static ULONG WINAPI RpcChannelBuffer_AddRef(LPRPCCHANNELBUFFER iface)
115 RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
116 return InterlockedIncrement(&This->refs);
119 static ULONG WINAPI ServerRpcChannelBuffer_Release(LPRPCCHANNELBUFFER iface)
121 RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
124 ref = InterlockedDecrement(&This->refs);
128 HeapFree(GetProcessHeap(), 0, This);
132 static ULONG WINAPI ClientRpcChannelBuffer_Release(LPRPCCHANNELBUFFER iface)
134 ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
137 ref = InterlockedDecrement(&This->super.refs);
141 RpcBindingFree(&This->bind);
142 HeapFree(GetProcessHeap(), 0, This);
146 static HRESULT WINAPI ServerRpcChannelBuffer_GetBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg, REFIID riid)
148 RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
149 RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
152 TRACE("(%p)->(%p,%p)\n", This, olemsg, riid);
154 status = I_RpcGetBuffer(msg);
156 TRACE("-- %ld\n", status);
158 return HRESULT_FROM_WIN32(status);
161 static HRESULT WINAPI ClientRpcChannelBuffer_GetBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg, REFIID riid)
163 ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
164 RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
165 RPC_CLIENT_INTERFACE *cif;
168 TRACE("(%p)->(%p,%p)\n", This, olemsg, riid);
170 cif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RPC_CLIENT_INTERFACE));
172 return E_OUTOFMEMORY;
174 cif->Length = sizeof(RPC_CLIENT_INTERFACE);
175 /* RPC interface ID = COM interface ID */
176 cif->InterfaceId.SyntaxGUID = *riid;
177 /* COM objects always have a version of 0.0 */
178 cif->InterfaceId.SyntaxVersion.MajorVersion = 0;
179 cif->InterfaceId.SyntaxVersion.MinorVersion = 0;
180 msg->RpcInterfaceInformation = cif;
181 msg->Handle = This->bind;
183 status = I_RpcGetBuffer(msg);
185 TRACE("-- %ld\n", status);
187 return HRESULT_FROM_WIN32(status);
190 static HRESULT WINAPI RpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
192 RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
196 TRACE("(%p)\n", msg);
198 status = I_RpcSendReceive(msg);
200 if (pstatus) *pstatus = status;
202 if (status == RPC_S_OK)
204 else if (status == RPC_S_CALL_FAILED)
205 hr = *(HRESULT *)msg->Buffer;
207 hr = HRESULT_FROM_WIN32(status);
209 TRACE("-- 0x%08lx\n", hr);
214 static HRESULT WINAPI ServerRpcChannelBuffer_FreeBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg)
216 RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
219 TRACE("(%p)\n", msg);
221 status = I_RpcFreeBuffer(msg);
223 TRACE("-- %ld\n", status);
225 return HRESULT_FROM_WIN32(status);
228 static HRESULT WINAPI ClientRpcChannelBuffer_FreeBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg)
230 RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
233 TRACE("(%p)\n", msg);
235 status = I_RpcFreeBuffer(msg);
237 HeapFree(GetProcessHeap(), 0, msg->RpcInterfaceInformation);
238 msg->RpcInterfaceInformation = NULL;
240 TRACE("-- %ld\n", status);
242 return HRESULT_FROM_WIN32(status);
245 static HRESULT WINAPI RpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface, DWORD* pdwDestContext, void** ppvDestContext)
247 FIXME("(%p,%p), stub!\n", pdwDestContext, ppvDestContext);
251 static HRESULT WINAPI RpcChannelBuffer_IsConnected(LPRPCCHANNELBUFFER iface)
254 /* native does nothing too */
258 static const IRpcChannelBufferVtbl ClientRpcChannelBufferVtbl =
260 RpcChannelBuffer_QueryInterface,
261 RpcChannelBuffer_AddRef,
262 ClientRpcChannelBuffer_Release,
263 ClientRpcChannelBuffer_GetBuffer,
264 RpcChannelBuffer_SendReceive,
265 ClientRpcChannelBuffer_FreeBuffer,
266 RpcChannelBuffer_GetDestCtx,
267 RpcChannelBuffer_IsConnected
270 static const IRpcChannelBufferVtbl ServerRpcChannelBufferVtbl =
272 RpcChannelBuffer_QueryInterface,
273 RpcChannelBuffer_AddRef,
274 ServerRpcChannelBuffer_Release,
275 ServerRpcChannelBuffer_GetBuffer,
276 RpcChannelBuffer_SendReceive,
277 ServerRpcChannelBuffer_FreeBuffer,
278 RpcChannelBuffer_GetDestCtx,
279 RpcChannelBuffer_IsConnected
282 /* returns a channel buffer for proxies */
283 HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid, IRpcChannelBuffer **chan)
285 ClientRpcChannelBuffer *This;
287 RPC_BINDING_HANDLE bind;
289 LPWSTR string_binding;
291 /* connect to the apartment listener thread */
292 get_rpc_endpoint(endpoint, oxid);
294 TRACE("proxy pipe: connecting to endpoint: %s\n", debugstr_w(endpoint));
296 status = RpcStringBindingComposeW(
304 if (status == RPC_S_OK)
306 status = RpcBindingFromStringBindingW(string_binding, &bind);
308 if (status == RPC_S_OK)
310 IPID ipid2 = *ipid; /* why can't RpcBindingSetObject take a const? */
311 status = RpcBindingSetObject(bind, &ipid2);
312 if (status != RPC_S_OK)
313 RpcBindingFree(&bind);
316 RpcStringFreeW(&string_binding);
319 if (status != RPC_S_OK)
321 ERR("Couldn't get binding for endpoint %s, status = %ld\n", debugstr_w(endpoint), status);
322 return HRESULT_FROM_WIN32(status);
325 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
328 RpcBindingFree(&bind);
329 return E_OUTOFMEMORY;
332 This->super.lpVtbl = &ClientRpcChannelBufferVtbl;
333 This->super.refs = 1;
336 *chan = (IRpcChannelBuffer*)This;
341 HRESULT RPC_CreateServerChannel(IRpcChannelBuffer **chan)
343 RpcChannelBuffer *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
345 return E_OUTOFMEMORY;
347 This->lpVtbl = &ServerRpcChannelBufferVtbl;
350 *chan = (IRpcChannelBuffer*)This;
356 HRESULT RPC_ExecuteCall(RPCOLEMESSAGE *msg, IRpcStubBuffer *stub)
358 /* FIXME: pass server channel buffer, but don't create it every time */
359 return IRpcStubBuffer_Invoke(stub, msg, NULL);
362 static void __RPC_STUB dispatch_rpc(RPC_MESSAGE *msg)
364 IRpcStubBuffer *stub;
368 RpcBindingInqObject(msg->Handle, &ipid);
370 stub = ipid_to_apt_and_stubbuffer(&ipid, &apt);
373 if (apt) COM_ApartmentRelease(apt);
374 /* ipid_to_apt_and_stubbuffer will already have logged the error */
375 return RpcRaiseException(RPC_E_DISCONNECTED);
378 /* Note: this is the important difference between STAs and MTAs - we
379 * always execute RPCs to STAs in the thread that originally created the
380 * apartment (i.e. the one that pumps messages to the window) */
381 if (apt->model & COINIT_APARTMENTTHREADED)
382 SendMessageW(apt->win, DM_EXECUTERPC, (WPARAM)msg, (LPARAM)stub);
384 RPC_ExecuteCall((RPCOLEMESSAGE *)msg, stub);
386 COM_ApartmentRelease(apt);
387 IRpcStubBuffer_Release(stub);
390 /* stub registration */
391 HRESULT RPC_RegisterInterface(REFIID riid)
393 struct registered_if *rif;
397 TRACE("(%s)\n", debugstr_guid(riid));
399 EnterCriticalSection(&csRegIf);
400 LIST_FOR_EACH_ENTRY(rif, ®istered_interfaces, struct registered_if, entry)
402 if (IsEqualGUID(&rif->If.InterfaceId.SyntaxGUID, riid))
411 TRACE("Creating new interface\n");
413 rif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*rif));
419 rif->If.Length = sizeof(RPC_SERVER_INTERFACE);
420 /* RPC interface ID = COM interface ID */
421 rif->If.InterfaceId.SyntaxGUID = *riid;
422 rif->If.DispatchTable = &rpc_dispatch;
423 /* all other fields are 0, including the version asCOM objects
424 * always have a version of 0.0 */
425 status = RpcServerRegisterIfEx(
426 (RPC_IF_HANDLE)&rif->If,
428 RPC_IF_OLE | RPC_IF_AUTOLISTEN,
429 RPC_C_LISTEN_MAX_CALLS_DEFAULT,
431 if (status == RPC_S_OK)
432 list_add_tail(®istered_interfaces, &rif->entry);
435 ERR("RpcServerRegisterIfEx failed with error %ld\n", status);
436 HeapFree(GetProcessHeap(), 0, rif);
437 hr = HRESULT_FROM_WIN32(status);
443 LeaveCriticalSection(&csRegIf);
447 /* stub unregistration */
448 void RPC_UnregisterInterface(REFIID riid)
450 struct registered_if *rif;
451 EnterCriticalSection(&csRegIf);
452 LIST_FOR_EACH_ENTRY(rif, ®istered_interfaces, struct registered_if, entry)
454 if (IsEqualGUID(&rif->If.InterfaceId.SyntaxGUID, riid))
458 #if 0 /* this is a stub in builtin and spams the console with FIXME's */
459 IID iid = *riid; /* RpcServerUnregisterIf doesn't take const IID */
460 RpcServerUnregisterIf((RPC_IF_HANDLE)&rif->If, &iid, 0);
461 list_remove(&rif->entry);
462 HeapFree(GetProcessHeap(), 0, rif);
468 LeaveCriticalSection(&csRegIf);
471 /* make the apartment reachable by other threads and processes and create the
472 * IRemUnknown object */
473 void RPC_StartRemoting(struct apartment *apt)
475 if (!InterlockedExchange(&apt->remoting_started, TRUE))
480 get_rpc_endpoint(endpoint, &apt->oxid);
482 status = RpcServerUseProtseqEpW(
484 RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
487 if (status != RPC_S_OK)
488 ERR("Couldn't register endpoint %s\n", debugstr_w(endpoint));
490 /* FIXME: move remote unknown exporting into this function */
492 start_apartment_remote_unknown();
496 static HRESULT create_server(REFCLSID rclsid)
498 static const WCHAR embedding[] = { ' ', '-','E','m','b','e','d','d','i','n','g',0 };
501 HRESULT hres = E_UNEXPECTED;
503 WCHAR exe[MAX_PATH+1];
504 DWORD exelen = sizeof(exe);
505 WCHAR command[MAX_PATH+sizeof(embedding)/sizeof(WCHAR)];
507 PROCESS_INFORMATION pinfo;
509 WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
511 sprintf(buf,"CLSID\\%s\\LocalServer32",xclsid);
512 hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
514 if (hres != ERROR_SUCCESS) {
515 WARN("CLSID %s not registered as LocalServer32\n", xclsid);
516 return REGDB_E_READREGDB; /* Probably */
519 memset(exe,0,sizeof(exe));
520 hres= RegQueryValueExW(key, NULL, NULL, NULL, (LPBYTE)exe, &exelen);
523 WARN("No default value for LocalServer32 key\n");
524 return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
527 memset(&sinfo,0,sizeof(sinfo));
528 sinfo.cb = sizeof(sinfo);
530 /* EXE servers are started with the -Embedding switch. MSDN also claims /Embedding is used,
531 * 9x does -Embedding, perhaps an 9x/NT difference?
534 strcpyW(command, exe);
535 strcatW(command, embedding);
537 TRACE("activating local server '%s' for %s\n", debugstr_w(command), xclsid);
539 if (!CreateProcessW(exe, command, NULL, NULL, FALSE, 0, NULL, NULL, &sinfo, &pinfo)) {
540 WARN("failed to run local server %s\n", debugstr_w(exe));
541 return HRESULT_FROM_WIN32(GetLastError());
543 CloseHandle(pinfo.hProcess);
544 CloseHandle(pinfo.hThread);
550 * start_local_service() - start a service given its name and parameters
552 static DWORD start_local_service(LPCWSTR name, DWORD num, LPWSTR *params)
554 SC_HANDLE handle, hsvc;
555 DWORD r = ERROR_FUNCTION_FAILED;
557 TRACE("Starting service %s %ld params\n", debugstr_w(name), num);
559 handle = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
562 hsvc = OpenServiceW(handle, name, SC_MANAGER_ALL_ACCESS);
565 if(StartServiceW(hsvc, num, (LPCWSTR*)params))
569 if (r == ERROR_SERVICE_ALREADY_RUNNING)
571 CloseServiceHandle(hsvc);
573 CloseServiceHandle(handle);
575 TRACE("StartService returned error %ld (%s)\n", r, r?"ok":"failed");
581 * create_local_service() - start a COM server in a service
583 * To start a Local Service, we read the AppID value under
584 * the class's CLSID key, then open the HKCR\\AppId key specified
585 * there and check for a LocalService value.
587 * Note: Local Services are not supported under Windows 9x
589 static HRESULT create_local_service(REFCLSID rclsid)
591 HRESULT hres = REGDB_E_READREGDB;
592 WCHAR buf[40], keyname[50];
593 static const WCHAR szClsId[] = { 'C','L','S','I','D','\\',0 };
594 static const WCHAR szAppId[] = { 'A','p','p','I','d',0 };
595 static const WCHAR szAppIdKey[] = { 'A','p','p','I','d','\\',0 };
596 static const WCHAR szLocalService[] = { 'L','o','c','a','l','S','e','r','v','i','c','e',0 };
597 static const WCHAR szServiceParams[] = {'S','e','r','v','i','c','e','P','a','r','a','m','s',0};
602 TRACE("Attempting to start Local service for %s\n", debugstr_guid(rclsid));
604 /* read the AppID value under the class's key */
605 strcpyW(keyname,szClsId);
606 StringFromGUID2(rclsid,&keyname[6],39);
607 r = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &hkey);
608 if (r!=ERROR_SUCCESS)
611 r = RegQueryValueExW(hkey, szAppId, NULL, &type, (LPBYTE)buf, &sz);
613 if (r!=ERROR_SUCCESS || type!=REG_SZ)
616 /* read the LocalService and ServiceParameters values from the AppID key */
617 strcpyW(keyname, szAppIdKey);
618 strcatW(keyname, buf);
619 r = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &hkey);
620 if (r!=ERROR_SUCCESS)
623 r = RegQueryValueExW(hkey, szLocalService, NULL, &type, (LPBYTE)buf, &sz);
624 if (r==ERROR_SUCCESS && type==REG_SZ)
627 LPWSTR args[1] = { NULL };
630 * FIXME: I'm not really sure how to deal with the service parameters.
631 * I suspect that the string returned from RegQueryValueExW
632 * should be split into a number of arguments by spaces.
633 * It would make more sense if ServiceParams contained a
634 * REG_MULTI_SZ here, but it's a REG_SZ for the services
635 * that I'm interested in for the moment.
637 r = RegQueryValueExW(hkey, szServiceParams, NULL, &type, NULL, &sz);
638 if (r == ERROR_SUCCESS && type == REG_SZ && sz)
640 args[0] = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sz);
642 RegQueryValueExW(hkey, szServiceParams, NULL, &type, (LPBYTE)args[0], &sz);
644 r = start_local_service(buf, num_args, args);
645 if (r==ERROR_SUCCESS)
647 HeapFree(GetProcessHeap(),0,args[0]);
654 #define PIPEPREF "\\\\.\\pipe\\"
656 /* FIXME: should call to rpcss instead */
657 HRESULT RPC_GetLocalClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
662 DWORD res, bufferlen;
663 char marshalbuffer[200];
665 LARGE_INTEGER seekto;
666 ULARGE_INTEGER newpos;
669 static const int MAXTRIES = 30; /* 30 seconds */
671 TRACE("rclsid=%s, iid=%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
673 strcpy(pipefn,PIPEPREF);
674 WINE_StringFromCLSID(rclsid,pipefn+strlen(PIPEPREF));
676 while (tries++ < MAXTRIES) {
677 TRACE("waiting for %s\n", pipefn);
679 WaitNamedPipeA( pipefn, NMPWAIT_WAIT_FOREVER );
680 hPipe = CreateFileA(pipefn, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
681 if (hPipe == INVALID_HANDLE_VALUE) {
683 if ( (hres = create_server(rclsid)) &&
684 (hres = create_local_service(rclsid)) )
688 WARN("Connecting to %s, no response yet, retrying: le is %lx\n",pipefn,GetLastError());
694 if (!ReadFile(hPipe,marshalbuffer,sizeof(marshalbuffer),&bufferlen,NULL)) {
695 FIXME("Failed to read marshal id from classfactory of %s.\n",debugstr_guid(rclsid));
699 TRACE("read marshal id from pipe\n");
704 if (tries >= MAXTRIES)
705 return E_NOINTERFACE;
707 hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
708 if (hres) return hres;
709 hres = IStream_Write(pStm,marshalbuffer,bufferlen,&res);
711 seekto.u.LowPart = 0;seekto.u.HighPart = 0;
712 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
714 TRACE("unmarshalling classfactory\n");
715 hres = CoUnmarshalInterface(pStm,&IID_IClassFactory,ppv);
717 IStream_Release(pStm);
722 struct local_server_params
728 /* FIXME: should call to rpcss instead */
729 static DWORD WINAPI local_server_thread(LPVOID param)
731 struct local_server_params * lsp = (struct local_server_params *)param;
735 IStream *pStm = lsp->stream;
737 unsigned char *buffer;
739 LARGE_INTEGER seekto;
740 ULARGE_INTEGER newpos;
743 TRACE("Starting threader for %s.\n",debugstr_guid(&lsp->clsid));
745 strcpy(pipefn,PIPEPREF);
746 WINE_StringFromCLSID(&lsp->clsid,pipefn+strlen(PIPEPREF));
748 HeapFree(GetProcessHeap(), 0, lsp);
750 hPipe = CreateNamedPipeA( pipefn, PIPE_ACCESS_DUPLEX,
751 PIPE_TYPE_BYTE|PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
752 4096, 4096, 500 /* 0.5 second timeout */, NULL );
754 if (hPipe == INVALID_HANDLE_VALUE)
756 FIXME("pipe creation failed for %s, le is %ld\n",pipefn,GetLastError());
761 if (!ConnectNamedPipe(hPipe,NULL)) {
762 ERR("Failure during ConnectNamedPipe %ld, ABORT!\n",GetLastError());
766 TRACE("marshalling IClassFactory to client\n");
768 hres = IStream_Stat(pStm,&ststg,0);
769 if (hres) return hres;
771 buflen = ststg.cbSize.u.LowPart;
772 buffer = HeapAlloc(GetProcessHeap(),0,buflen);
773 seekto.u.LowPart = 0;
774 seekto.u.HighPart = 0;
775 hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
777 FIXME("IStream_Seek failed, %lx\n",hres);
781 hres = IStream_Read(pStm,buffer,buflen,&res);
783 FIXME("Stream Read failed, %lx\n",hres);
787 WriteFile(hPipe,buffer,buflen,&res,NULL);
788 FlushFileBuffers(hPipe);
789 DisconnectNamedPipe(hPipe);
791 TRACE("done marshalling IClassFactory\n");
794 IStream_Release(pStm);
798 void RPC_StartLocalServer(REFCLSID clsid, IStream *stream)
802 struct local_server_params *lsp = HeapAlloc(GetProcessHeap(), 0, sizeof(*lsp));
805 lsp->stream = stream;
807 thread = CreateThread(NULL, 0, local_server_thread, lsp, 0, &tid);
809 /* FIXME: failure handling */