Eric Pouech : kernel32: Set the new definition for an activation context, and implement adding/releasing references to it.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 9 07:43:10 CDT 2007


Module: wine
Branch: master
Commit: fe3869388ab2e7dadd091ccc7878ba9bafb5dc3e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fe3869388ab2e7dadd091ccc7878ba9bafb5dc3e

Author: Eric Pouech <eric.pouech at wanadoo.fr>
Date:   Mon May  7 21:49:47 2007 +0200

kernel32: Set the new definition for an activation context, and implement adding/releasing references to it.

---

 dlls/kernel32/actctx.c |   71 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/dlls/kernel32/actctx.c b/dlls/kernel32/actctx.c
index fbf50d0..06bc8e5 100644
--- a/dlls/kernel32/actctx.c
+++ b/dlls/kernel32/actctx.c
@@ -46,6 +46,14 @@ WINE_DEFAULT_DEBUG_CHANNEL(actctx);
 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
 #define ACTCTX_FAKE_COOKIE ((ULONG_PTR) 0xf00bad)
 
+#define ACTCTX_MAGIC       0xC07E3E11
+
+struct actctx
+{
+    ULONG               magic;
+    LONG                ref_count;
+};
+
 /***********************************************************************
  * CreateActCtxA (KERNEL32.@)
  *
@@ -130,15 +138,44 @@ done:
  */
 HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
 {
-  FIXME("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
+    struct actctx*      actctx;
+    DWORD               ret = ERROR_SUCCESS;
 
-  if (!pActCtx)
-    return INVALID_HANDLE_VALUE;
-  if (pActCtx->cbSize != sizeof *pActCtx)
-    return INVALID_HANDLE_VALUE;
-  if (pActCtx->dwFlags & ~ACTCTX_FLAGS_ALL)
+    TRACE("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
+
+    if (!pActCtx || pActCtx->cbSize != sizeof(*pActCtx) ||
+        (pActCtx->dwFlags & ~ACTCTX_FLAGS_ALL))
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return INVALID_HANDLE_VALUE;
+    }
+    actctx = HeapAlloc(GetProcessHeap(), 0, sizeof(*actctx));
+    if (!actctx) return INVALID_HANDLE_VALUE;
+
+    actctx->magic = ACTCTX_MAGIC;
+    actctx->ref_count = 1;
+
+    if (ret == ERROR_SUCCESS)
+    {
+        return (HANDLE)actctx;
+    }
+
+    ReleaseActCtx((HANDLE)actctx);
+    SetLastError(ret);
     return INVALID_HANDLE_VALUE;
-  return ACTCTX_FAKE_HANDLE;
+}
+
+static struct actctx* check_actctx(HANDLE h)
+{
+    struct actctx*      actctx = (struct actctx*)h;
+
+    switch (actctx->magic)
+    {
+    case ACTCTX_MAGIC: return actctx;
+    default:
+        SetLastError(ERROR_INVALID_HANDLE);
+        return NULL;
+    }
 }
 
 /***********************************************************************
@@ -204,7 +241,12 @@ BOOL WINAPI GetCurrentActCtx(HANDLE* phActCtx)
  */
 void WINAPI AddRefActCtx(HANDLE hActCtx)
 {
-  FIXME("%p\n", hActCtx);
+    struct actctx*      actctx;
+
+    TRACE("%p\n", hActCtx);
+
+    if ((actctx = check_actctx(hActCtx)))
+        InterlockedIncrement( &actctx->ref_count );
 }
 
 /***********************************************************************
@@ -214,7 +256,18 @@ void WINAPI AddRefActCtx(HANDLE hActCtx)
  */
 void WINAPI ReleaseActCtx(HANDLE hActCtx)
 {
-  FIXME("%p\n", hActCtx);
+    struct actctx*      actctx;
+
+    TRACE("%p\n", hActCtx);
+
+    if ((actctx = check_actctx(hActCtx)))
+    {
+        if (!InterlockedDecrement( &actctx->ref_count ))
+        {
+            actctx->magic = 0;
+            HeapFree(GetProcessHeap(), 0, actctx);
+        }
+    }
 }
 
 /***********************************************************************




More information about the wine-cvs mailing list