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
21 #include "d3drm_private.h"
23 /***********************************************************************
26 BOOL WINAPI
DllMain(HINSTANCE inst
, DWORD reason
, void *reserved
)
30 case DLL_WINE_PREATTACH
:
31 return FALSE
; /* prefer native version */
32 case DLL_PROCESS_ATTACH
:
33 DisableThreadLibraryCalls( inst
);
39 void d3drm_object_init(struct d3drm_object
*object
, const char *classname
)
43 list_init(&object
->destroy_callbacks
);
44 object
->classname
= classname
;
48 struct destroy_callback
51 D3DRMOBJECTCALLBACK cb
;
55 HRESULT
d3drm_object_add_destroy_callback(struct d3drm_object
*object
, D3DRMOBJECTCALLBACK cb
, void *ctx
)
57 struct destroy_callback
*callback
;
60 return D3DRMERR_BADVALUE
;
62 if (!(callback
= heap_alloc(sizeof(*callback
))))
68 list_add_head(&object
->destroy_callbacks
, &callback
->entry
);
72 HRESULT
d3drm_object_delete_destroy_callback(struct d3drm_object
*object
, D3DRMOBJECTCALLBACK cb
, void *ctx
)
74 struct destroy_callback
*callback
;
77 return D3DRMERR_BADVALUE
;
79 LIST_FOR_EACH_ENTRY(callback
, &object
->destroy_callbacks
, struct destroy_callback
, entry
)
81 if (callback
->cb
== cb
&& callback
->ctx
== ctx
)
83 list_remove(&callback
->entry
);
92 HRESULT
d3drm_object_get_class_name(struct d3drm_object
*object
, DWORD
*size
, char *name
)
99 req_size
= strlen(object
->classname
) + 1;
100 if (name
&& *size
< req_size
)
106 memcpy(name
, object
->classname
, req_size
);
111 HRESULT
d3drm_object_get_name(struct d3drm_object
*object
, DWORD
*size
, char *name
)
118 req_size
= object
->name
? strlen(object
->name
) + 1 : 0;
119 if (name
&& *size
< req_size
)
125 memcpy(name
, object
->name
, req_size
);
135 HRESULT
d3drm_object_set_name(struct d3drm_object
*object
, const char *name
)
139 heap_free(object
->name
);
144 req_size
= strlen(name
) + 1;
145 if (!(object
->name
= heap_alloc(req_size
)))
146 return E_OUTOFMEMORY
;
147 memcpy(object
->name
, name
, req_size
);
153 void d3drm_object_cleanup(IDirect3DRMObject
*iface
, struct d3drm_object
*object
)
155 struct destroy_callback
*callback
, *callback2
;
157 LIST_FOR_EACH_ENTRY_SAFE(callback
, callback2
, &object
->destroy_callbacks
, struct destroy_callback
, entry
)
159 callback
->cb(iface
, callback
->ctx
);
160 list_remove(&callback
->entry
);
164 heap_free(object
->name
);