Release 2.9.
[wine.git] / dlls / d3drm / d3drm_main.c
blob9fbd8d5f9532ad0a99293a74432d147590ee181f
1 /*
2 * Copyright 2004 Ivan Leo Puoti
3 * Copyright 2010 Christian Costa
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "initguid.h"
24 #include "d3drm_private.h"
26 /***********************************************************************
27 * DllMain (D3DRM.@)
29 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
31 switch(reason)
33 case DLL_WINE_PREATTACH:
34 return FALSE; /* prefer native version */
35 case DLL_PROCESS_ATTACH:
36 DisableThreadLibraryCalls( inst );
37 break;
39 return TRUE;
42 void d3drm_object_init(struct d3drm_object *object)
44 object->ref = 1;
45 object->appdata = 0;
46 list_init(&object->destroy_callbacks);
49 struct destroy_callback
51 struct list entry;
52 D3DRMOBJECTCALLBACK cb;
53 void *ctx;
56 HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
58 struct destroy_callback *callback;
60 if (!cb)
61 return D3DRMERR_BADVALUE;
63 callback = HeapAlloc(GetProcessHeap(), 0, sizeof(*callback));
64 if (!callback)
65 return E_OUTOFMEMORY;
67 callback->cb = cb;
68 callback->ctx = ctx;
70 list_add_head(&object->destroy_callbacks, &callback->entry);
71 return D3DRM_OK;
74 HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
76 struct destroy_callback *callback;
78 if (!cb)
79 return D3DRMERR_BADVALUE;
81 LIST_FOR_EACH_ENTRY(callback, &object->destroy_callbacks, struct destroy_callback, entry)
83 if (callback->cb == cb && callback->ctx == ctx)
85 list_remove(&callback->entry);
86 HeapFree(GetProcessHeap(), 0, callback);
87 break;
91 return D3DRM_OK;
94 void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
96 struct destroy_callback *callback, *callback2;
98 LIST_FOR_EACH_ENTRY_SAFE(callback, callback2, &object->destroy_callbacks, struct destroy_callback, entry)
100 callback->cb(iface, callback->ctx);
101 list_remove(&callback->entry);
102 HeapFree(GetProcessHeap(), 0, callback);