user32: Implement IDI_SHIELD.
[wine.git] / dlls / d3drm / d3drm_main.c
blob1bef5340be3aaa726a359749c0d6080d38f9914c
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, const char *classname)
44 object->ref = 1;
45 object->appdata = 0;
46 list_init(&object->destroy_callbacks);
47 object->classname = classname;
48 object->name = NULL;
51 struct destroy_callback
53 struct list entry;
54 D3DRMOBJECTCALLBACK cb;
55 void *ctx;
58 HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
60 struct destroy_callback *callback;
62 if (!cb)
63 return D3DRMERR_BADVALUE;
65 callback = HeapAlloc(GetProcessHeap(), 0, sizeof(*callback));
66 if (!callback)
67 return E_OUTOFMEMORY;
69 callback->cb = cb;
70 callback->ctx = ctx;
72 list_add_head(&object->destroy_callbacks, &callback->entry);
73 return D3DRM_OK;
76 HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
78 struct destroy_callback *callback;
80 if (!cb)
81 return D3DRMERR_BADVALUE;
83 LIST_FOR_EACH_ENTRY(callback, &object->destroy_callbacks, struct destroy_callback, entry)
85 if (callback->cb == cb && callback->ctx == ctx)
87 list_remove(&callback->entry);
88 HeapFree(GetProcessHeap(), 0, callback);
89 break;
93 return D3DRM_OK;
96 HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name)
98 DWORD req_size;
100 if (!size)
101 return E_INVALIDARG;
103 req_size = strlen(object->classname) + 1;
104 if (name && *size < req_size)
105 return E_INVALIDARG;
107 *size = req_size;
109 if (name)
110 memcpy(name, object->classname, req_size);
112 return D3DRM_OK;
115 HRESULT d3drm_object_get_name(struct d3drm_object *object, DWORD *size, char *name)
117 DWORD req_size;
119 if (!size)
120 return E_INVALIDARG;
122 req_size = object->name ? strlen(object->name) + 1 : 0;
123 if (name && *size < req_size)
124 return E_INVALIDARG;
126 if (name)
128 if (object->name)
129 memcpy(name, object->name, req_size);
130 else if (*size)
131 *name = 0;
134 *size = req_size;
136 return D3DRM_OK;
139 HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name)
141 DWORD req_size;
143 HeapFree(GetProcessHeap(), 0, object->name);
144 object->name = NULL;
146 if (name)
148 req_size = strlen(name) + 1;
149 if (!(object->name = HeapAlloc(GetProcessHeap(), 0, req_size)))
150 return E_OUTOFMEMORY;
151 memcpy(object->name, name, req_size);
154 return D3DRM_OK;
157 void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
159 struct destroy_callback *callback, *callback2;
161 LIST_FOR_EACH_ENTRY_SAFE(callback, callback2, &object->destroy_callbacks, struct destroy_callback, entry)
163 callback->cb(iface, callback->ctx);
164 list_remove(&callback->entry);
165 HeapFree(GetProcessHeap(), 0, callback);
168 HeapFree(GetProcessHeap(), 0, object->name);
169 object->name = NULL;