ReactOS  0.4.13-dev-73-gcfe54aa
ole_server.c File Reference
#include <windows.h>
#include <exdisp.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <assert.h>
#include "wine/test.h"
#include <initguid.h>
Include dependency graph for ole_server.c:

Go to the source code of this file.

Classes

struct  winetest_info
 
struct  UnknownImpl
 
struct  ClassFactoryImpl
 

Macros

#define COBJMACROS
 
#define CONST_VTABLE
 
#define GUID_NAME(guid)   { &IID_##guid, #guid }
 

Functions

 DEFINE_GUID (CLSID_WineTestObject, 0xdeadbeef, 0xdead, 0xbeef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef)
 
 DEFINE_GUID (CLSID_UnknownUnmarshal, 0x4c1e39e1, 0xe3e3, 0x4296, 0xaa, 0x86, 0xec, 0x93, 0x8d, 0x89, 0x6e, 0x92)
 
static const chardebugstr_guid (const GUID *guid)
 
static UnknownImplimpl_from_IUnknown (IUnknown *iface)
 
static HRESULT WINAPI UnknownImpl_QueryInterface (IUnknown *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI UnknownImpl_AddRef (IUnknown *iface)
 
static ULONG WINAPI UnknownImpl_Release (IUnknown *iface)
 
static ClassFactoryImplimpl_from_IClassFactory (IClassFactory *iface)
 
static HRESULT WINAPI ClassFactoryImpl_QueryInterface (IClassFactory *iface, REFIID iid, void **ppv)
 
static ULONG WINAPI ClassFactoryImpl_AddRef (IClassFactory *iface)
 
static ULONG WINAPI ClassFactoryImpl_Release (IClassFactory *iface)
 
static HRESULT WINAPI ClassFactoryImpl_CreateInstance (IClassFactory *iface, IUnknown *punkouter, REFIID iid, void **ppv)
 
static HRESULT WINAPI ClassFactoryImpl_LockServer (IClassFactory *iface, BOOL lock)
 
static void ole_server (void)
 
static BOOL register_server (const char *server, BOOL inproc_handler)
 
static void unregister_server (void)
 
static HANDLE start_server (const char *argv0)
 
 START_TEST (ole_server)
 

Variables

struct {
   const GUID *   guid
 
   const char *   name
 
guid_name []
 
static LONG obj_ref
 
static LONG class_ref
 
static LONG server_locks
 
static const IUnknownVtbl UnknownImpl_Vtbl
 
static const IClassFactoryVtbl ClassFactoryImpl_Vtbl
 
static ClassFactoryImpl factory = { { &ClassFactoryImpl_Vtbl }, 0 }
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file ole_server.c.

◆ CONST_VTABLE

#define CONST_VTABLE

Definition at line 22 of file ole_server.c.

◆ GUID_NAME

#define GUID_NAME (   guid)    { &IID_##guid, #guid }

Function Documentation

◆ ClassFactoryImpl_AddRef()

static ULONG WINAPI ClassFactoryImpl_AddRef ( IClassFactory iface)
static

Definition at line 172 of file ole_server.c.

173 {
176 
178 
179  trace("server: factory_AddRef: %p, ref %u\n", iface, ref);
180  return ref;
181 }
#define trace(...)
Definition: kmt_test.h:217
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
static LONG class_ref
Definition: ole_server.c:61
static ClassFactoryImpl * impl_from_IClassFactory(IClassFactory *iface)
Definition: ole_server.c:146
#define InterlockedIncrement
Definition: armddk.h:53
unsigned int ULONG
Definition: retypes.h:1

◆ ClassFactoryImpl_CreateInstance()

static HRESULT WINAPI ClassFactoryImpl_CreateInstance ( IClassFactory iface,
IUnknown punkouter,
REFIID  iid,
void **  ppv 
)
static

Definition at line 194 of file ole_server.c.

196 {
198  HRESULT hr;
199 
200  trace("server: factory_CreateInstance: %p,%s,%p\n", iface, debugstr_guid(iid), ppv);
201 
202  if (punkouter) return CLASS_E_NOAGGREGATION;
203 
204  unknown = HeapAlloc(GetProcessHeap(), 0, sizeof(*unknown));
205  if (!unknown) return E_OUTOFMEMORY;
206 
207  unknown->IUnknown_iface.lpVtbl = &UnknownImpl_Vtbl;
208  unknown->ref = 0;
209  IUnknown_AddRef(&unknown->IUnknown_iface);
210 
211  hr = IUnknown_QueryInterface(&unknown->IUnknown_iface, iid, ppv);
212  IUnknown_Release(&unknown->IUnknown_iface);
213 
214  return hr;
215 }
#define trace(...)
Definition: kmt_test.h:217
HRESULT hr
Definition: shlfolder.c:183
REFIID LPVOID * ppv
Definition: atlbase.h:39
static const char * debugstr_guid(const GUID *guid)
Definition: ole_server.c:63
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
Definition: id3.c:18
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
static const IUnknownVtbl UnknownImpl_Vtbl
Definition: ole_server.c:133

◆ ClassFactoryImpl_LockServer()

static HRESULT WINAPI ClassFactoryImpl_LockServer ( IClassFactory iface,
BOOL  lock 
)
static

Definition at line 217 of file ole_server.c.

218 {
220 
221  trace("server: factory_LockServer: %p,%d, ref %u\n", iface, lock, ref);
222  return S_OK;
223 }
#define trace(...)
Definition: kmt_test.h:217
rwlock_t lock
Definition: tcpcore.h:1163
Definition: send.c:47
static LONG server_locks
Definition: ole_server.c:61
#define InterlockedDecrement
Definition: armddk.h:52
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
unsigned int ULONG
Definition: retypes.h:1

◆ ClassFactoryImpl_QueryInterface()

static HRESULT WINAPI ClassFactoryImpl_QueryInterface ( IClassFactory iface,
REFIID  iid,
void **  ppv 
)
static

Definition at line 151 of file ole_server.c.

153 {
155 
156  trace("server: factory_QueryInterface: %p,%s,%p\n", iface, debugstr_guid(iid), ppv);
157 
158  if (!ppv) return E_INVALIDARG;
159 
160  if (IsEqualIID(&IID_IUnknown, iid) ||
162  {
163  IClassFactory_AddRef(&This->IClassFactory_iface);
164  *ppv = &This->IClassFactory_iface;
165  return S_OK;
166  }
167 
168  *ppv = NULL;
169  return E_NOINTERFACE;
170 }
#define trace(...)
Definition: kmt_test.h:217
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID LPVOID * ppv
Definition: atlbase.h:39
static const char * debugstr_guid(const GUID *guid)
Definition: ole_server.c:63
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
const GUID IID_IUnknown
static ClassFactoryImpl * impl_from_IClassFactory(IClassFactory *iface)
Definition: ole_server.c:146
#define S_OK
Definition: intsafe.h:59
const GUID IID_IClassFactory
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:90

◆ ClassFactoryImpl_Release()

static ULONG WINAPI ClassFactoryImpl_Release ( IClassFactory iface)
static

Definition at line 183 of file ole_server.c.

184 {
187 
189 
190  trace("server: factory_Release: %p, ref %u\n", iface, ref);
191  return ref;
192 }
#define trace(...)
Definition: kmt_test.h:217
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
static LONG class_ref
Definition: ole_server.c:61
static ClassFactoryImpl * impl_from_IClassFactory(IClassFactory *iface)
Definition: ole_server.c:146
#define InterlockedDecrement
Definition: armddk.h:52
unsigned int ULONG
Definition: retypes.h:1

◆ debugstr_guid()

static const char* debugstr_guid ( const GUID guid)
static

Definition at line 63 of file ole_server.c.

64 {
65  int i;
66 
67  if (!guid) return "(null)";
68 
69  for (i = 0; i < ARRAY_SIZE(guid_name); i++)
70  {
72  return guid_name[i].name;
73  }
74 
75  return wine_dbgstr_guid(guid);
76 }
const GUID * guid
Definition: ole_server.c:42
static const struct @1615 guid_name[]
const char * wine_dbgstr_guid(const GUID *guid)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ARRAY_SIZE(a)
Definition: main.h:24
Definition: name.c:36
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:90

Referenced by ClassFactoryImpl_CreateInstance(), ClassFactoryImpl_QueryInterface(), and UnknownImpl_QueryInterface().

◆ DEFINE_GUID() [1/2]

DEFINE_GUID ( CLSID_WineTestObject  ,
0xdeadbeef  ,
0xdead  ,
0xbeef  ,
0xde  ,
0xad  ,
0xbe  ,
0xef  ,
0xde  ,
0xad  ,
0xbe  ,
0xef   
)

◆ DEFINE_GUID() [2/2]

DEFINE_GUID ( CLSID_UnknownUnmarshal  ,
0x4c1e39e1  ,
0xe3e3  ,
0x4296  ,
0xaa  ,
0x86  ,
0xec  ,
0x93  ,
0x8d  ,
0x89  ,
0x6e  ,
0x92   
)

◆ impl_from_IClassFactory()

static ClassFactoryImpl* impl_from_IClassFactory ( IClassFactory iface)
inlinestatic

Definition at line 146 of file ole_server.c.

147 {
148  return CONTAINING_RECORD(iface, ClassFactoryImpl, IClassFactory_iface);
149 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by ClassFactoryImpl_AddRef(), ClassFactoryImpl_QueryInterface(), and ClassFactoryImpl_Release().

◆ impl_from_IUnknown()

static UnknownImpl* impl_from_IUnknown ( IUnknown iface)
inlinestatic

Definition at line 85 of file ole_server.c.

86 {
87  return CONTAINING_RECORD(iface, UnknownImpl, IUnknown_iface);
88 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by UnknownImpl_AddRef(), UnknownImpl_QueryInterface(), and UnknownImpl_Release().

◆ ole_server()

static void ole_server ( void  )
static

Definition at line 236 of file ole_server.c.

237 {
238  HRESULT hr;
239  DWORD key;
240 
241  trace("server: starting %u\n", GetCurrentProcessId());
242 
244  if (hr == S_OK)
245  {
246  trace("server: registering class object\n");
247  hr = CoRegisterClassObject(&CLSID_WineTestObject, (IUnknown *)&factory,
248  CLSCTX_SERVER, REGCLS_MULTIPLEUSE, &key);
249  if (hr == S_OK)
250  {
251  HANDLE done_event, init_done_event;
252 
253  done_event = OpenEventA(SYNCHRONIZE, FALSE, "ole_server_done_event");
254  ok(done_event != 0, "server: OpenEvent error %d\n", GetLastError());
255  init_done_event = OpenEventA(EVENT_MODIFY_STATE, FALSE, "ole_server_init_done_event");
256  ok(init_done_event != 0, "server: OpenEvent error %d\n", GetLastError());
257 
258  SetEvent(init_done_event);
259 
260  trace("server: waiting for requests\n");
261  WaitForSingleObject(done_event, INFINITE);
262 
263  /* 1 remainining class ref is supposed to be cleared by CoRevokeClassObject */
264  ok(class_ref == 1, "expected 1 class refs, got %d\n", class_ref);
265  ok(!obj_ref, "expected 0 object refs, got %d\n", obj_ref);
266  ok(!server_locks, "expected 0 server locks, got %d\n", server_locks);
267 
268  CloseHandle(done_event);
269  CloseHandle(init_done_event);
270  if (0)
271  {
272  /* calling CoRevokeClassObject terminates process under Win7 */
273  trace("call CoRevokeClassObject\n");
275  trace("ret CoRevokeClassObject\n");
276  }
277  }
278  trace("server: call CoUninitialize\n");
279  CoUninitialize();
280  trace("server: ret CoUninitialize\n");
281  }
282 
283  trace("server: exiting %u\n", GetCurrentProcessId());
284 }
#define trace(...)
Definition: kmt_test.h:217
#define CloseHandle
Definition: compat.h:398
HRESULT hr
Definition: shlfolder.c:183
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
Definition: main.c:440
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:615
#define ok(value,...)
static LONG obj_ref
Definition: ole_server.c:61
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI DECLSPEC_HOTPATCH CoRevokeClassObject(DWORD dwRegister)
Definition: compobj.c:1089
static LONG class_ref
Definition: ole_server.c:61
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
static LONG server_locks
Definition: ole_server.c:61
HKEY key
Definition: reg.c:42
#define SYNCHRONIZE
Definition: nt_native.h:61
HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk, DWORD dwClsContext, DWORD flags, LPDWORD lpdwRegister)
Definition: compobj.c:2806
#define S_OK
Definition: intsafe.h:59
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
#define INFINITE
Definition: serial.h:102
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1188
Definition: path.c:42

Referenced by START_TEST().

◆ register_server()

static BOOL register_server ( const char server,
BOOL  inproc_handler 
)
static

Definition at line 287 of file ole_server.c.

288 {
289  static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0};
290  DWORD ret;
291  HKEY root;
292  WCHAR buf[39 + 6];
293  char server_path[MAX_PATH];
294 
295  lstrcpyA(server_path, server);
296  lstrcatA(server_path, " ole_server");
297 
298  lstrcpyW(buf, clsidW);
299  StringFromGUID2(&CLSID_WineTestObject, buf + 6, 39);
300 
303  if (ret == ERROR_SUCCESS)
304  {
305  ret = RegSetValueA(root, "LocalServer32", REG_SZ, server_path, strlen(server_path));
306  ok(ret == ERROR_SUCCESS, "RegSetValue error %u\n", ret);
307 
308  if (inproc_handler)
309  {
310  ret = RegSetValueA(root, "InprocHandler32", REG_SZ, "ole32.dll", 9);
311  ok(ret == ERROR_SUCCESS, "RegSetValue error %u\n", ret);
312  }
313 
314  RegCloseKey(root);
315  }
316 
317  return ret == ERROR_SUCCESS;
318 }
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define KEY_READ
Definition: nt_native.h:1023
struct _root root
LONG WINAPI RegSetValueA(HKEY hKeyOriginal, LPCSTR lpSubKey, DWORD dwType, LPCSTR lpData, DWORD cbData)
Definition: reg.c:4990
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
#define KEY_WRITE
Definition: nt_native.h:1031
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
static const WCHAR clsidW[]
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2343
unsigned long DWORD
Definition: ntddk_ex.h:95
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
int ret
#define lstrcpyW
Definition: compat.h:406
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

◆ start_server()

static HANDLE start_server ( const char argv0)
static

Definition at line 344 of file ole_server.c.

345 {
347  STARTUPINFOA si;
349  char cmdline[MAX_PATH * 2];
350  BOOL ret;
351 
352  memset(&si, 0, sizeof(si));
353  si.cb = sizeof(si);
357  si.hStdError = si.hStdOutput;
358 
359  sa.nLength = sizeof(sa);
360  sa.lpSecurityDescriptor = NULL;
361  sa.bInheritHandle = TRUE;
362 
363  sprintf(cmdline, "\"%s\" ole_server -server", argv0);
364  ret = CreateProcessA(argv0, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
365  ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
366  if (!ret) return 0;
367 
368  CloseHandle(pi.hThread);
369  return pi.hProcess;
370 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
DWORD dwFlags
Definition: winbase.h:807
TCHAR * cmdline
Definition: stretchblt.cpp:32
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
DWORD cb
Definition: winbase.h:796
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4772
#define MAX_PATH
Definition: compat.h:26
HANDLE hStdOutput
Definition: winbase.h:812
static DWORD pi
Definition: protocol.c:150
int ret
static char argv0[MAX_PATH]
Definition: shlexec.c:56
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
HANDLE hStdInput
Definition: winbase.h:811
#define memset(x, y, z)
Definition: compat.h:39
HANDLE hStdError
Definition: winbase.h:813
static struct sockaddr_in sa
Definition: adnsresfilter.c:69

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( ole_server  )

Definition at line 372 of file ole_server.c.

373 {
374  CLSID clsid = CLSID_WineTestObject;
375  HRESULT hr;
377  IUnknown *unknown;
378  IOleObject *oleobj;
379  IRunnableObject *runobj;
380  DWORD ret;
381  HANDLE mapping, done_event, init_done_event, process;
382  struct winetest_info *info;
383  int argc;
384  char **argv;
385 
386  mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, "winetest_ole_server");
387  ok(mapping != 0, "CreateFileMapping failed\n");
389 
391 
392  done_event = CreateEventA(NULL, TRUE, FALSE, "ole_server_done_event");
393  ok(done_event != 0, "CreateEvent error %d\n", GetLastError());
394  init_done_event = CreateEventA(NULL, TRUE, FALSE, "ole_server_init_done_event");
395  ok(init_done_event != 0, "CreateEvent error %d\n", GetLastError());
396 
397  if (argc > 2)
398  {
399  if (!lstrcmpiA(argv[2], "-Embedding"))
400  {
401  trace("server: Refusing to be run by ole32\n");
402  return;
403  }
404 
405  if (!lstrcmpiA(argv[2], "-server"))
406  {
407  info->child_failures = 0;
408  ole_server();
409  info->child_failures = winetest_get_failures();
410  return;
411  }
412 
413  trace("server: Unknown parameter: %s\n", argv[2]);
414  return;
415  }
416 
417  if (!register_server(argv[0], FALSE))
418  {
419  win_skip("not enough permissions to create a server CLSID key\n");
420  return;
421  }
422 
423  if (!(process = start_server(argv[0])))
424  {
426  return;
427  }
428  WaitForSingleObject(init_done_event, 5000);
429 
431  ok(hr == S_OK, "OleInitialize error %#x\n", hr);
432 
433  hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_HANDLER, &IID_IUnknown, (void **)&unknown);
434  ok(hr == REGDB_E_CLASSNOTREG, "expected REGDB_E_CLASSNOTREG, got %#x\n", hr);
435 
436  if (!register_server(argv[0], TRUE))
437  {
438  win_skip("not enough permissions to create a server CLSID key\n");
440  return;
441  }
442 
443  trace("call CoCreateInstance(&IID_NULL)\n");
444  hr = CoCreateInstance(&clsid, NULL, CLSCTX_LOCAL_SERVER, &IID_NULL, (void **)&unknown);
445  trace("ret CoCreateInstance(&IID_NULL)\n");
446  ok(hr == E_NOINTERFACE, "expected E_NOINTERFACE, got %#x\n", hr);
447 
448  /* in-process handler supports IID_IUnknown starting from Vista */
449  trace("call CoCreateInstance(&IID_IUnknown)\n");
450  hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_HANDLER, &IID_IUnknown, (void **)&unknown);
451  trace("ret CoCreateInstance(&IID_IUnknown)\n");
452  ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG) /* XP,win2000 and earlier */, "CoCreateInstance(IID_IUnknown) error %#x\n", hr);
453  if (hr != S_OK)
454  {
455  win_skip("In-process handler doesn't support IID_IUnknown on this platform\n");
456  goto test_local_server;
457  }
458 
459  trace("call CoCreateInstance(&IID_IOleObject)\n");
460  hr = CoCreateInstance(&clsid, NULL, CLSCTX_LOCAL_SERVER, &IID_IOleObject, (void **)&oleobj);
461  trace("ret CoCreateInstance(&IID_IOleObject)\n");
462  ok(hr == E_NOINTERFACE, "expected E_NOINTERFACE, got %#x\n", hr);
463 
464  trace("call IUnknown_QueryInterface(&IID_IRunnableObject)\n");
465  hr = IUnknown_QueryInterface(unknown, &IID_IRunnableObject, (void **)&runobj);
466  trace("ret IUnknown_QueryInterface(&IID_IRunnableObject)\n");
467  ok(hr == S_OK, "QueryInterface(&IID_IRunnableObject) error %#x\n", hr);
468 
469  ret = IRunnableObject_IsRunning(runobj);
470  ok(!ret, "expected 0, got %d\n", ret);
471 
472  trace("call OleRun\n");
473  hr = OleRun(unknown);
474  trace("ret OleRun\n");
475 todo_wine
476  ok(hr == S_OK, "OleRun error %#x\n", hr);
477 
478  ret = IRunnableObject_IsRunning(runobj);
479 todo_wine
480  ok(ret == 1, "expected 1, got %d\n", ret);
481 
482  trace("call IRunnableObject_Release\n");
483  ret = IRunnableObject_Release(runobj);
484  trace("ret IRunnableObject_Release\n");
485  ok(ret == 1, "expected ref 1, got %u\n", ret);
486 
487  trace("call IUnknown_QueryInterface(&IID_IOleObject)\n");
488  hr = IUnknown_QueryInterface(unknown, &IID_IOleObject, (void **)&oleobj);
489  trace("ret IUnknown_QueryInterface(&IID_IOleObject)\n");
490  ok(hr == S_OK, "QueryInterface(&IID_IOleObject) error %#x\n", hr);
491 
492  trace("call IOleObject_Release\n");
493  ret = IOleObject_Release(oleobj);
494  trace("ret IOleObject_Release\n");
495  ok(ret == 1, "expected ref 1, got %u\n", ret);
496 
497  trace("call IUnknown_Release\n");
498  ret = IUnknown_Release(unknown);
499  trace("ret IUnknown_Release\n");
500  ok(!ret, "expected ref 0, got %u\n", ret);
501 
503  /* local server supports IID_IUnknown */
504  trace("call CoCreateInstance(&IID_IUnknown)\n");
505  hr = CoCreateInstance(&clsid, NULL, CLSCTX_LOCAL_SERVER, &IID_IUnknown, (void **)&unknown);
506  trace("ret CoCreateInstance(&IID_IUnknown)\n");
507  ok(hr == S_OK, "CoCreateInstance(IID_IUnknown) error %#x\n", hr);
508 
509  trace("call IUnknown_QueryInterface(&IID_IRunnableObject)\n");
510  hr = IUnknown_QueryInterface(unknown, &IID_IRunnableObject, (void **)&runobj);
511  trace("ret IUnknown_QueryInterface(&IID_IRunnableObject)\n");
512  ok(hr == E_NOINTERFACE, "expected E_NOINTERFACE, got %#x\n", hr);
513 
514  trace("call OleRun\n");
515  hr = OleRun(unknown);
516  trace("ret OleRun\n");
517  ok(hr == S_OK, "OleRun error %#x\n", hr);
518 
519  trace("call IUnknown_QueryInterface(&IID_IOleObject)\n");
520  hr = IUnknown_QueryInterface(unknown, &IID_IOleObject, (void **)&oleobj);
521  trace("ret IUnknown_QueryInterface(&IID_IOleObject)\n");
522  ok(hr == E_NOINTERFACE, "expected E_NOINTERFACE, got %#x\n", hr);
523 
524  trace("call IUnknown_Release\n");
525  ret = IUnknown_Release(unknown);
526  trace("ret IUnknown_Release\n");
527  ok(!ret, "expected ref 0, got %u\n", ret);
528 
529  trace("call CoGetClassObject(&IID_IClassFactory)\n");
530  hr = CoGetClassObject(&clsid, CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void **)&factory);
531  trace("ret CoGetClassObject(&IID_IClassFactory)\n");
532  ok(hr == S_OK, "CoGetClassObject error %#x\n", hr);
533 
534  trace("call IClassFactory_CreateInstance(&IID_NULL)\n");
535  hr = IClassFactory_CreateInstance(factory, NULL, &IID_NULL, (void **)&oleobj);
536  trace("ret IClassFactory_CreateInstance(&IID_NULL)\n");
537  ok(hr == E_NOINTERFACE, "expected E_NOINTERFACE, got %#x\n", hr);
538 
539  trace("call IClassFactory_CreateInstance(&IID_IOleObject)\n");
540  hr = IClassFactory_CreateInstance(factory, NULL, &IID_IOleObject, (void **)&oleobj);
541  trace("ret IClassFactory_CreateInstance(&IID_IOleObject)\n");
542  ok(hr == E_NOINTERFACE, "expected E_NOINTERFACE, got %#x\n", hr);
543 
544  trace("call IClassFactory_Release\n");
545  ret = IClassFactory_Release(factory);
546  trace("ret IClassFactory_Release\n");
547  ok(!ret, "expected ref 0, got %u\n", ret);
548 
549  trace("signalling termination\n");
550  SetEvent(done_event);
551  ret = WaitForSingleObject(process, 10000);
552  ok(ret == WAIT_OBJECT_0, "server failed to terminate\n");
553 
554  OleUninitialize();
555 
557 
558  if (info->child_failures)
559  {
560  trace("%d failures in child process\n", info->child_failures);
561  winetest_add_failures(info->child_failures);
562  }
563 }
static int argc
Definition: ServiceArgs.c:12
#define trace(...)
Definition: kmt_test.h:217
LONG winetest_get_failures(void)
#define TRUE
Definition: types.h:120
void winetest_add_failures(LONG new_failures)
#define E_NOINTERFACE
Definition: winerror.h:2364
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
#define MapViewOfFile
Definition: compat.h:402
HRESULT hr
Definition: shlfolder.c:183
static void ole_server(void)
Definition: ole_server.c:236
HRESULT WINAPI DECLSPEC_HOTPATCH OleRun(LPUNKNOWN pUnknown)
Definition: ole2.c:1208
static HANDLE process
Definition: process.c:76
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define argv
Definition: mplay32.c:18
struct _test_info info[]
Definition: SetCursorPos.c:19
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
Definition: main.c:440
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:583
#define FILE_MAP_READ
Definition: compat.h:427
static HANDLE start_server(const char *argv0)
Definition: ole_server.c:344
HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3012
const GUID IID_IOleObject
#define WAIT_OBJECT_0
Definition: winbase.h:387
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define FILE_MAP_WRITE
Definition: winbase.h:154
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
Definition: id3.c:18
int winetest_get_mainargs(char ***pargv)
static void unregister_server(void)
Definition: ole_server.c:320
static void test_local_server(void)
Definition: marshal.c:3818
int ret
REFCLSID clsid
Definition: msctf.c:84
#define IID_NULL
Definition: guiddef.h:93
#define todo_wine
Definition: test.h:154
const GUID IID_IRunnableObject
#define broken(x)
Definition: _sntprintf.h:21
static BOOL register_server(const char *server, BOOL inproc_handler)
Definition: ole_server.c:287
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define S_OK
Definition: intsafe.h:59
#define REGDB_E_CLASSNOTREG
Definition: winerror.h:2696
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
static ClassFactoryImpl factory
Definition: ole_server.c:234
const GUID IID_IClassFactory
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:233
#define win_skip
Definition: test.h:141
HANDLE NTAPI CreateFileMappingA(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes, IN DWORD flProtect, IN DWORD dwMaximumSizeHigh, IN DWORD dwMaximumSizeLow, IN LPCSTR lpName)
Definition: filemap.c:23
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ UnknownImpl_AddRef()

static ULONG WINAPI UnknownImpl_AddRef ( IUnknown iface)
static

Definition at line 110 of file ole_server.c.

111 {
114 
116 
117  trace("server: unknown_AddRef: %p, ref %u\n", iface, ref);
118  return ref;
119 }
#define trace(...)
Definition: kmt_test.h:217
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
static LONG obj_ref
Definition: ole_server.c:61
#define InterlockedIncrement
Definition: armddk.h:53
unsigned int ULONG
Definition: retypes.h:1
static UnknownImpl * impl_from_IUnknown(IUnknown *iface)
Definition: ole_server.c:85

◆ UnknownImpl_QueryInterface()

static HRESULT WINAPI UnknownImpl_QueryInterface ( IUnknown iface,
REFIID  iid,
void **  ppv 
)
static

Definition at line 90 of file ole_server.c.

92 {
94 
95  trace("server: unknown_QueryInterface: %p,%s,%p\n", iface, debugstr_guid(iid), ppv);
96 
97  if (!ppv) return E_INVALIDARG;
98 
99  if (IsEqualIID(&IID_IUnknown, iid))
100  {
101  *ppv = &This->IUnknown_iface;
102  IUnknown_AddRef(&This->IUnknown_iface);
103  return S_OK;
104  }
105 
106  *ppv = NULL;
107  return E_NOINTERFACE;
108 }
#define trace(...)
Definition: kmt_test.h:217
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID LPVOID * ppv
Definition: atlbase.h:39
static const char * debugstr_guid(const GUID *guid)
Definition: ole_server.c:63
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
const GUID IID_IUnknown
#define S_OK
Definition: intsafe.h:59
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:90
static UnknownImpl * impl_from_IUnknown(IUnknown *iface)
Definition: ole_server.c:85

◆ UnknownImpl_Release()

static ULONG WINAPI UnknownImpl_Release ( IUnknown iface)
static

Definition at line 121 of file ole_server.c.

122 {
125 
127 
128  trace("server: unknown_Release: %p, ref %u\n", iface, ref);
129  if (ref == 0) HeapFree(GetProcessHeap(), 0, This);
130  return ref;
131 }
#define trace(...)
Definition: kmt_test.h:217
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
static LONG obj_ref
Definition: ole_server.c:61
#define GetProcessHeap()
Definition: compat.h:395
#define InterlockedDecrement
Definition: armddk.h:52
unsigned int ULONG
Definition: retypes.h:1
#define HeapFree(x, y, z)
Definition: compat.h:394
static UnknownImpl * impl_from_IUnknown(IUnknown *iface)
Definition: ole_server.c:85

◆ unregister_server()

static void unregister_server ( void  )
static

Definition at line 320 of file ole_server.c.

321 {
322  static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0};
323  DWORD ret;
324  HKEY root;
325  WCHAR buf[39 + 6];
326 
327  lstrcpyW(buf, clsidW);
328  StringFromGUID2(&CLSID_WineTestObject, buf + 6, 39);
329 
331  DELETE, NULL, &root, NULL);
332  if (ret == ERROR_SUCCESS)
333  {
334  ret = RegDeleteKeyA(root, "InprocHandler32");
335  ok(ret == ERROR_SUCCESS, "RegDeleteKey error %u\n", ret);
336  ret = RegDeleteKeyA(root, "LocalServer32");
337  ok(ret == ERROR_SUCCESS, "RegDeleteKey error %u\n", ret);
338  ret = RegDeleteKeyA(root, "");
339  ok(ret == ERROR_SUCCESS, "RegDeleteKey error %u\n", ret);
340  RegCloseKey(root);
341  }
342 }
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
struct _root root
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR clsidW[]
__wchar_t WCHAR
Definition: xmlstorage.h:180
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2343
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1225
#define lstrcpyW
Definition: compat.h:406
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define DELETE
Definition: nt_native.h:57

Referenced by START_TEST().

Variable Documentation

◆ class_ref

LONG class_ref
static

Definition at line 61 of file ole_server.c.

Referenced by ClassFactoryImpl_AddRef(), ClassFactoryImpl_Release(), and ole_server().

◆ ClassFactoryImpl_Vtbl

const IClassFactoryVtbl ClassFactoryImpl_Vtbl
static
Initial value:
=
{
}
static HRESULT WINAPI ClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID iid, void **ppv)
Definition: ole_server.c:151
static HRESULT WINAPI ClassFactoryImpl_LockServer(IClassFactory *iface, BOOL lock)
Definition: ole_server.c:217
static ULONG WINAPI ClassFactoryImpl_AddRef(IClassFactory *iface)
Definition: ole_server.c:172
static HRESULT WINAPI ClassFactoryImpl_CreateInstance(IClassFactory *iface, IUnknown *punkouter, REFIID iid, void **ppv)
Definition: ole_server.c:194
static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface)
Definition: ole_server.c:183

Definition at line 225 of file ole_server.c.

◆ factory

◆ guid

const GUID* guid

Definition at line 42 of file ole_server.c.

Referenced by debugstr_guid().

◆ guid_name

const { ... } guid_name[]
Initial value:
=
{
#define GUID_NAME(guid)
{ &CLSID_IdentityUnmarshal, "CLSID_IdentityUnmarshal" },
{ &CLSID_UnknownUnmarshal, "CLSID_UnknownUnmarshal" },
}
const CLSID CLSID_IdentityUnmarshal
#define GUID_NAME(guid)

Referenced by debugstr_guid().

◆ name

Definition at line 43 of file ole_server.c.

◆ obj_ref

LONG obj_ref
static

Definition at line 61 of file ole_server.c.

Referenced by ole_server(), UnknownImpl_AddRef(), and UnknownImpl_Release().

◆ server_locks

LONG server_locks
static

◆ UnknownImpl_Vtbl

const IUnknownVtbl UnknownImpl_Vtbl
static
Initial value:
=
{
}
static ULONG WINAPI UnknownImpl_AddRef(IUnknown *iface)
Definition: ole_server.c:110
static ULONG WINAPI UnknownImpl_Release(IUnknown *iface)
Definition: ole_server.c:121
static HRESULT WINAPI UnknownImpl_QueryInterface(IUnknown *iface, REFIID iid, void **ppv)
Definition: ole_server.c:90

Definition at line 133 of file ole_server.c.

Referenced by ClassFactoryImpl_CreateInstance().