- use Interlocked* functions in AddRef and Release.
- store the result of the Interlocked functions and use only this.

diff --git a/dlls/ddraw/d3ddevice/main.c b/dlls/ddraw/d3ddevice/main.c
index 646fa14..4e81d38 100644
--- a/dlls/ddraw/d3ddevice/main.c
+++ b/dlls/ddraw/d3ddevice/main.c
@@ -260,16 +260,22 @@
 Main_IDirect3DDeviceImpl_7_3T_2T_1T_AddRef(LPDIRECT3DDEVICE7 iface)
 {
     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
-    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
-    return ++(This->ref);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
+
+    return ref;
 }
 
 ULONG WINAPI
 Main_IDirect3DDeviceImpl_7_3T_2T_1T_Release(LPDIRECT3DDEVICE7 iface)
 {
     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         int i;
 	/* Release texture associated with the device */
 	for (i = 0; i < MAX_TEXTURES; i++) {
@@ -280,7 +286,7 @@
 	HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
diff --git a/dlls/ddraw/d3ddevice/mesa.c b/dlls/ddraw/d3ddevice/mesa.c
index bfaada8..bc4c43f 100644
--- a/dlls/ddraw/d3ddevice/mesa.c
+++ b/dlls/ddraw/d3ddevice/mesa.c
@@ -381,9 +381,11 @@
 {
     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
     IDirect3DDeviceGLImpl *glThis = (IDirect3DDeviceGLImpl *) This;
+    ULONG ref = InterlockedDecrement(&This->ref);
     
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         int i;
 	IDirectDrawSurfaceImpl *surface = This->surface, *surf;
 	
@@ -442,7 +444,7 @@
 	HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
diff --git a/dlls/ddraw/d3dexecutebuffer.c b/dlls/ddraw/d3dexecutebuffer.c
index 909ee6a..ad83685 100644
--- a/dlls/ddraw/d3dexecutebuffer.c
+++ b/dlls/ddraw/d3dexecutebuffer.c
@@ -519,16 +519,22 @@
 Main_IDirect3DExecuteBufferImpl_1_AddRef(LPDIRECT3DEXECUTEBUFFER iface)
 {
     ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
-    FIXME("(%p/%p)->()incrementing from %lu.\n", This, iface, This->ref );
-    return ++(This->ref);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    FIXME("(%p/%p)->()incrementing from %lu.\n", This, iface, ref - 1);
+
+    return ref;
 }
 
 ULONG WINAPI
 Main_IDirect3DExecuteBufferImpl_1_Release(LPDIRECT3DEXECUTEBUFFER iface)
 {
     ICOM_THIS_FROM(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, iface);
-    TRACE("(%p/%p)->()decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->()decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         if ((This->desc.lpData != NULL) && This->need_free)
 	    HeapFree(GetProcessHeap(),0,This->desc.lpData);
         HeapFree(GetProcessHeap(),0,This->vertex_data);
@@ -537,7 +543,7 @@
 	return 0;
     }
 
-    return This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
diff --git a/dlls/ddraw/d3dlight.c b/dlls/ddraw/d3dlight.c
index 801444d..174a1b6 100644
--- a/dlls/ddraw/d3dlight.c
+++ b/dlls/ddraw/d3dlight.c
@@ -53,20 +53,26 @@
 Main_IDirect3DLightImpl_1_AddRef(LPDIRECT3DLIGHT iface)
 {
     ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
-    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
-    return ++(This->ref);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
+
+    return ref;
 }
 
 ULONG WINAPI
 Main_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
 {
     ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
@@ -191,14 +197,16 @@
 {
     ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
     IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
+    ULONG ref = InterlockedDecrement(&This->ref);
     
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         ((IDirect3DGLImpl *) This->d3d->d3d_private)->light_released(This->d3d, glThis->light_num);
         HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
diff --git a/dlls/ddraw/d3dmaterial.c b/dlls/ddraw/d3dmaterial.c
index 3b39f02..8216794 100644
--- a/dlls/ddraw/d3dmaterial.c
+++ b/dlls/ddraw/d3dmaterial.c
@@ -85,20 +85,26 @@
 Main_IDirect3DMaterialImpl_3_2T_1T_AddRef(LPDIRECT3DMATERIAL3 iface)
 {
     ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
-    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
-    return ++(This->ref);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
+
+    return ref;
 }
 
 ULONG WINAPI
 Main_IDirect3DMaterialImpl_3_2T_1T_Release(LPDIRECT3DMATERIAL3 iface)
 {
     ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
diff --git a/dlls/ddraw/d3dvertexbuffer.c b/dlls/ddraw/d3dvertexbuffer.c
index ca8d732..7775b87 100644
--- a/dlls/ddraw/d3dvertexbuffer.c
+++ b/dlls/ddraw/d3dvertexbuffer.c
@@ -73,21 +73,27 @@
 Main_IDirect3DVertexBufferImpl_7_1T_AddRef(LPDIRECT3DVERTEXBUFFER7 iface)
 {
     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
-    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
-    return ++(This->ref);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
+
+    return ref;
 }
 
 ULONG WINAPI
 Main_IDirect3DVertexBufferImpl_7_1T_Release(LPDIRECT3DVERTEXBUFFER7 iface)
 {
     ICOM_THIS_FROM(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, iface);
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (--(This->ref) == 0) {
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (ref == 0) {
         HeapFree(GetProcessHeap(), 0, This->vertices);
 	HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
diff --git a/dlls/ddraw/d3dviewport.c b/dlls/ddraw/d3dviewport.c
index 0daadb2..12fd1a2 100644
--- a/dlls/ddraw/d3dviewport.c
+++ b/dlls/ddraw/d3dviewport.c
@@ -126,20 +126,26 @@
 Main_IDirect3DViewportImpl_3_2_1_AddRef(LPDIRECT3DVIEWPORT3 iface)
 {
     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
-    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
-    return ++(This->ref);
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
+
+    return ref;
 }
 
 ULONG WINAPI
 Main_IDirect3DViewportImpl_3_2_1_Release(LPDIRECT3DVIEWPORT3 iface)
 {
     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (!--(This->ref)) {
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
+
+    if (!ref) {
         HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 
diff --git a/dlls/ddraw/dclipper/main.c b/dlls/ddraw/dclipper/main.c
index 0195ea2..a0f69d7 100644
--- a/dlls/ddraw/dclipper/main.c
+++ b/dlls/ddraw/dclipper/main.c
@@ -114,14 +114,16 @@
 
 ULONG WINAPI Main_DirectDrawClipper_Release(LPDIRECTDRAWCLIPPER iface) {
     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    if (--This->ref == 0)
+    TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
+
+    if (ref == 0)
     {
 	Main_DirectDrawClipper_Destroy(This);
 	return 0;
     }
-    else return This->ref;
+    else return ref;
 }
 
 /***********************************************************************
@@ -211,7 +213,7 @@
 	|| IsEqualGUID(&IID_IDirectDrawClipper, riid))
     {
 	*ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
-	++This->ref;
+	InterlockedIncrement(&This->ref);
 	return S_OK;
     }
     else
@@ -223,8 +225,11 @@
 ULONG WINAPI Main_DirectDrawClipper_AddRef( LPDIRECTDRAWCLIPPER iface )
 {
     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    TRACE("(%p)->() incrementing from %lu.\n", This, This->ref );
-    return ++This->ref;
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1);
+
+    return ref;
 }
 
 HRESULT WINAPI Main_DirectDrawClipper_GetHWnd(
diff --git a/dlls/ddraw/ddraw/main.c b/dlls/ddraw/ddraw/main.c
index 6e0feee..a2f47f5 100644
--- a/dlls/ddraw/ddraw/main.c
+++ b/dlls/ddraw/ddraw/main.c
@@ -149,17 +149,18 @@
 
 ULONG WINAPI Main_DirectDraw_AddRef(LPDIRECTDRAW7 iface) {
     IDirectDrawImpl *This = (IDirectDrawImpl *)iface;
-    TRACE("(%p)->() incrementing from %lu.\n", This, This->ref );
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    return ++This->ref;
+    TRACE("(%p)->() incrementing from %lu.\n", This, ref -1);
+
+    return ref;
 }
 
 ULONG WINAPI Main_DirectDraw_Release(LPDIRECTDRAW7 iface) {
-    ULONG ref;
     IDirectDrawImpl *This = (IDirectDrawImpl *)iface;
-    TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    ref = --This->ref;
+    TRACE("(%p)->() decrementing from %lu.\n", This, ref +1);
 
     if (ref == 0)
     {
diff --git a/dlls/ddraw/dpalette/main.c b/dlls/ddraw/dpalette/main.c
index 5328378..9e955e7 100644
--- a/dlls/ddraw/dpalette/main.c
+++ b/dlls/ddraw/dpalette/main.c
@@ -208,21 +208,26 @@
 Main_DirectDrawPalette_Release(LPDIRECTDRAWPALETTE iface)
 {
     IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
-    TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    if (!--This->ref)
+    TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
+
+    if (!ref)
     {
 	Main_DirectDrawPalette_Destroy(This);
 	return 0;
     }
 
-    return This->ref;
+    return ref;
 }
 
 ULONG WINAPI Main_DirectDrawPalette_AddRef(LPDIRECTDRAWPALETTE iface) {
     IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
-    TRACE("(%p)->() incrementing from %lu.\n", This, This->ref );
-    return ++This->ref;
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1);
+
+    return ref;
 }
 
 HRESULT WINAPI
diff --git a/dlls/ddraw/dsurface/main.c b/dlls/ddraw/dsurface/main.c
index 7b982cb..b7aa27d 100644
--- a/dlls/ddraw/dsurface/main.c
+++ b/dlls/ddraw/dsurface/main.c
@@ -125,10 +125,11 @@
 ULONG WINAPI Main_DirectDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface)
 {
     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE("(%p)->(): decreasing from %ld\n", This, This->ref);
+    TRACE("(%p)->(): decreasing from %ld\n", This, ref + 1);
     
-    if (--This->ref == 0)
+    if (ref == 0)
     {
 	if (This->aux_release)
 	    This->aux_release(This->aux_ctx, This->aux_data);
@@ -139,16 +140,17 @@
 	return 0;
     }
 
-    return This->ref;
+    return ref;
 }
 
 ULONG WINAPI Main_DirectDrawSurface_AddRef(LPDIRECTDRAWSURFACE7 iface)
 {
     IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p)->(): increasing from %ld\n", This, This->ref);
+    TRACE("(%p)->(): increasing from %ld\n", This, ref - 1);
     
-    return ++This->ref;
+    return ref;
 }
 
 HRESULT WINAPI
@@ -164,7 +166,7 @@
 	|| IsEqualGUID(&IID_IDirectDrawSurface7, riid)
 	|| IsEqualGUID(&IID_IDirectDrawSurface4, riid))
     {
-	This->ref++;
+        InterlockedIncrement(&This->ref);
 	*ppObj = ICOM_INTERFACE(This, IDirectDrawSurface7);
 	return S_OK;
     }
@@ -172,13 +174,13 @@
 	     || IsEqualGUID(&IID_IDirectDrawSurface2, riid)
 	     || IsEqualGUID(&IID_IDirectDrawSurface3, riid))
     {
-	This->ref++;
+        InterlockedIncrement(&This->ref);
 	*ppObj = ICOM_INTERFACE(This, IDirectDrawSurface3);
 	return S_OK;
     }
     else if (IsEqualGUID(&IID_IDirectDrawGammaControl, riid))
     {
-	This->ref++;
+        InterlockedIncrement(&This->ref);
 	*ppObj = ICOM_INTERFACE(This, IDirectDrawGammaControl);
 	return S_OK;
     }
@@ -199,7 +201,7 @@
 	*ppObj = ICOM_INTERFACE(d3ddevimpl, IDirect3DDevice);
 	TRACE(" returning Direct3DDevice interface at %p.\n", *ppObj);
 	
-	This->ref++; /* No idea if this is correct.. Need to check using real Windows */
+	InterlockedIncrement(&This->ref); /* No idea if this is correct.. Need to check using real Windows */
 	return ret_value;
     }
     else if (IsEqualGUID( &IID_IDirect3DTexture, riid ) ||
@@ -230,7 +232,7 @@
 	    *ppObj = ICOM_INTERFACE(This, IDirect3DTexture2);
 	    TRACE(" returning Direct3DTexture2 interface at %p.\n", *ppObj);
 	}
-	This->ref++;
+	InterlockedIncrement(&This->ref);
 	return ret_value;
     }
 #endif
diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index 5a38a46..c6ae458 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -496,10 +496,11 @@
 static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface)
 {
     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p)->() incrementing from %ld.\n", This, This->ref);
+    TRACE("(%p)->() incrementing from %ld.\n", This, ref - 1);
     
-    return InterlockedIncrement(&This->ref);
+    return ref;
 }
 
 static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface)
diff --git a/dlls/ole32/errorinfo.c b/dlls/ole32/errorinfo.c
index ca46ac5..74f4cac 100644
--- a/dlls/ole32/errorinfo.c
+++ b/dlls/ole32/errorinfo.c
@@ -149,13 +149,13 @@
  converts a objectpointer to This
  */
 #define _IErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtei)))
-#define _ICOM_THIS_From_IErrorInfo(class, name) class* This = (class*)(((char*)name)-_IErrorInfo_Offset);
+#define _ICOM_THIS_From_IErrorInfo(class, name) class* This = (class*)(((char*)name)-_IErrorInfo_Offset)
 
 #define _ICreateErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtcei)))
-#define _ICOM_THIS_From_ICreateErrorInfo(class, name) class* This = (class*)(((char*)name)-_ICreateErrorInfo_Offset);
+#define _ICOM_THIS_From_ICreateErrorInfo(class, name) class* This = (class*)(((char*)name)-_ICreateErrorInfo_Offset)
 
 #define _ISupportErrorInfo_Offset ((int)(&(((ErrorInfoImpl*)0)->lpvtsei)))
-#define _ICOM_THIS_From_ISupportErrorInfo(class, name) class* This = (class*)(((char*)name)-_ISupportErrorInfo_Offset);
+#define _ICOM_THIS_From_ISupportErrorInfo(class, name) class* This = (class*)(((char*)name)-_ISupportErrorInfo_Offset)
 
 /*
  converts This to a objectpointer
@@ -227,15 +227,17 @@
 	IErrorInfo* iface)
 {
 	_ICOM_THIS_From_IErrorInfo(ErrorInfoImpl, iface);
-	TRACE("(%p)->(count=%lu)\n",This,This->ref);
+        ULONG ref = InterlockedDecrement(&This->ref);
 
-	if (!InterlockedDecrement(&This->ref))
+	TRACE("(%p)->(count=%lu)\n",This,ref+1);
+
+	if (!ref)
 	{
 	  TRACE("-- destroying IErrorInfo(%p)\n",This);
 	  HeapFree(GetProcessHeap(),0,This);
 	  return 0;
 	}
-	return This->ref;
+	return ref;
 }
 
 static HRESULT WINAPI IErrorInfoImpl_GetGUID(
diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c
index bb80208..0d505bd 100644
--- a/dlls/ole32/ifs.c
+++ b/dlls/ole32/ifs.c
@@ -394,10 +394,11 @@
 {
 
     _MallocSpy *This = (_MallocSpy *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE ("(%p)->(count=%lu)\n", This, This->ref);
+    TRACE ("(%p)->(count=%lu)\n", This, ref - 1);
 
-    return ++(This->ref);
+    return ref;
 }
 
 /******************************************************************************
@@ -410,13 +411,14 @@
 {
 
     _MallocSpy *This = (_MallocSpy *)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    TRACE ("(%p)->(count=%lu)\n", This, This->ref);
+    TRACE ("(%p)->(count=%lu)\n", This, ref + 1);
 
-    if (!--(This->ref)) {
+    if (!ref) {
         /* our allocation list MUST be empty here */
     }
-    return This->ref;
+    return ref;
 }
 
 static ULONG WINAPI IMallocSpy_fnPreAlloc(LPMALLOCSPY iface, ULONG cbRequest)
diff --git a/dlls/ole32/oleobj.c b/dlls/ole32/oleobj.c
index 45efbc0..370020f 100644
--- a/dlls/ole32/oleobj.c
+++ b/dlls/ole32/oleobj.c
@@ -181,8 +181,11 @@
   LPOLEADVISEHOLDER iface)
 {
   OleAdviseHolderImpl *This = (OleAdviseHolderImpl *)iface;
-  TRACE("(%p)->(ref=%ld)\n", This, This->ref);
-  return ++(This->ref);
+  ULONG ref = InterlockedIncrement(&This->ref);
+
+  TRACE("(%p)->(ref=%ld)\n", This, ref - 1);
+
+  return ref;
 }
 
 /******************************************************************************
diff --git a/dlls/oleaut32/tests/safearray.c b/dlls/oleaut32/tests/safearray.c
index 08094f2..1bfa894b 100644
--- a/dlls/oleaut32/tests/safearray.c
+++ b/dlls/oleaut32/tests/safearray.c
@@ -96,13 +96,13 @@
 static ULONG CALLBACK IRecordInfoImpl_AddRef(IRecordInfo *iface)
 {
   IRecordInfoImpl* This=(IRecordInfoImpl*)iface;
-  return ++This->ref;
+  return InterlockedIncrement(&This->ref);
 }
 
 static ULONG CALLBACK IRecordInfoImpl_Release(IRecordInfo *iface)
 {
   IRecordInfoImpl* This=(IRecordInfoImpl*)iface;
-  return --This->ref;
+  return InterlockedDecrement(&This->ref);
 }
 
 static BOOL fail_GetSize; /* Whether to fail the GetSize call */
diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c
index 713aa44..e2bac39 100644
--- a/dlls/oleaut32/typelib.c
+++ b/dlls/oleaut32/typelib.c
@@ -847,7 +847,7 @@
 {
     ITypeLib2Vtbl *lpVtbl;
     ITypeCompVtbl *lpVtblTypeComp;
-    UINT ref;
+    ULONG ref;
     TLIBATTR LibAttr;            /* guid,lcid,syskind,version,flags */
 
     /* strings can be stored in tlb as multibyte strings BUT they are *always*
@@ -958,7 +958,7 @@
 {
     ITypeInfo2Vtbl *lpVtbl;
     ITypeCompVtbl  *lpVtblTypeComp;
-    UINT ref;
+    ULONG ref;
     TYPEATTR TypeAttr ;         /* _lots_ of type information. */
     ITypeLibImpl * pTypeLib;        /* back pointer to typelib */
     int index;                  /* index in this typelib; */
@@ -1276,7 +1276,7 @@
 
 static void dump_TypeInfo(ITypeInfoImpl * pty)
 {
-    TRACE("%p ref=%u\n", pty, pty->ref);
+    TRACE("%p ref=%lu\n", pty, pty->ref);
     TRACE("attr:%s\n", debugstr_guid(&(pty->TypeAttr.guid)));
     TRACE("kind:%s\n", typekind_desc[pty->TypeAttr.typekind]);
     TRACE("fct:%u var:%u impl:%u\n",
@@ -3434,10 +3434,11 @@
 static ULONG WINAPI ITypeLib2_fnAddRef( ITypeLib2 *iface)
 {
     ITypeLibImpl *This = (ITypeLibImpl *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p)->ref was %u\n",This, This->ref);
+    TRACE("(%p)->ref was %lu\n",This, ref - 1);
 
-    return ++(This->ref);
+    return ref;
 }
 
 /* ITypeLib::Release
@@ -3445,12 +3446,11 @@
 static ULONG WINAPI ITypeLib2_fnRelease( ITypeLib2 *iface)
 {
     ITypeLibImpl *This = (ITypeLibImpl *)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    --(This->ref);
+    TRACE("(%p)->(%lu)\n",This, ref);
 
-    TRACE("(%p)->(%u)\n",This, This->ref);
-
-    if (!This->ref)
+    if (!ref)
     {
       /* remove cache entry */
       TRACE("removing from cache list\n");
@@ -3493,7 +3493,7 @@
       return 0;
     }
 
-    return This->ref;
+    return ref;
 }
 
 /* ITypeLib::GetTypeInfoCount
@@ -4110,12 +4110,12 @@
 static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface)
 {
     ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    ++(This->ref);
     ITypeLib2_AddRef((ITypeLib2*)This->pTypeLib);
 
-    TRACE("(%p)->ref is %u\n",This, This->ref);
-    return This->ref;
+    TRACE("(%p)->ref is %lu\n",This, ref);
+    return ref;
 }
 
 /* ITypeInfo::Release
@@ -4123,12 +4123,11 @@
 static ULONG WINAPI ITypeInfo_fnRelease(ITypeInfo2 *iface)
 {
     ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    --(This->ref);
+    TRACE("(%p)->(%lu)\n",This, ref);
 
-    TRACE("(%p)->(%u)\n",This, This->ref);
-
-    if (This->ref)   {
+    if (ref)   {
       /* We don't release ITypeLib when ref=0 becouse
          it means that funtion is called by ITypeLi2_Release */
       ITypeLib2_Release((ITypeLib2*)This->pTypeLib);
@@ -4156,7 +4155,7 @@
       HeapFree(GetProcessHeap(),0,This);
       return 0;
     }
-    return This->ref;
+    return ref;
 }
 
 /* ITypeInfo::GetTypeAttr
diff --git a/dlls/oleaut32/typelib2.c b/dlls/oleaut32/typelib2.c
index f9c88d8..a51423f 100644
--- a/dlls/oleaut32/typelib2.c
+++ b/dlls/oleaut32/typelib2.c
@@ -1142,10 +1142,11 @@
 static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
 {
     ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p)->ref was %u\n",This, This->ref);
+    TRACE("(%p)->ref was %lu\n",This, ref - 1);
 
-    return ++(This->ref);
+    return ref;
 }
 
 /******************************************************************************
@@ -1156,12 +1157,11 @@
 static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
 {
     ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    --(This->ref);
+    TRACE("(%p)->(%lu)\n",This, ref);
 
-    TRACE("(%p)->(%u)\n",This, This->ref);
-
-    if (!This->ref) {
+    if (!ref) {
 	if (This->typelib) {
 	    ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
 	    This->typelib = NULL;
@@ -1172,7 +1172,7 @@
 	return 0;
     }
 
-    return This->ref;
+    return ref;
 }
 
 
@@ -3009,10 +3009,11 @@
 static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
 {
     ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
 
-    TRACE("(%p)->ref was %u\n",This, This->ref);
+    TRACE("(%p)->ref was %lu\n",This, ref - 1);
 
-    return ++(This->ref);
+    return ref;
 }
 
 /******************************************************************************
@@ -3023,12 +3024,11 @@
 static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
 {
     ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
 
-    --(This->ref);
+    TRACE("(%p)->(%lu)\n",This, ref);
 
-    TRACE("(%p)->(%u)\n",This, This->ref);
-
-    if (!This->ref) {
+    if (!ref) {
 	int i;
 
 	for (i = 0; i < MSFT_SEG_MAX; i++) {
@@ -3050,7 +3050,7 @@
 	return 0;
     }
 
-    return This->ref;
+    return ref;
 }