mciwave: Fix wave format first, then compute position.
[wine] / dlls / sti / sti_main.c
1 /*
2  * Copyright (C) 2002 Aric Stewart for CodeWeavers
3  * Copyright (C) 2009 Damjan Jovanovic
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <stdarg.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winerror.h"
28 #include "objbase.h"
29 #include "sti.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(sti);
34
35 typedef HRESULT (*fnCreateInstance)(REFIID riid, IUnknown *pUnkOuter, LPVOID *ppObj);
36
37 typedef struct
38 {
39     const struct IClassFactoryVtbl *vtbl;
40     fnCreateInstance pfnCreateInstance;
41 } sti_cf;
42
43 static inline sti_cf *impl_from_IClassFactory( IClassFactory *iface )
44 {
45     return (sti_cf *)((char *)iface - FIELD_OFFSET( sti_cf, vtbl ));
46 }
47
48 static HRESULT sti_create( REFIID riid, IUnknown *pUnkOuter, LPVOID *ppObj )
49 {
50     if (pUnkOuter != NULL && !IsEqualIID(riid, &IID_IUnknown))
51         return CLASS_E_NOAGGREGATION;
52
53     if (IsEqualGUID(riid, &IID_IUnknown))
54         return StiCreateInstanceW(GetCurrentProcess(), STI_VERSION_REAL | STI_VERSION_FLAG_UNICODE, (PSTIW*) ppObj, pUnkOuter);
55     else if (IsEqualGUID(riid, &IID_IStillImageW))
56         return StiCreateInstanceW(GetCurrentProcess(), STI_VERSION_REAL | STI_VERSION_FLAG_UNICODE, (PSTIW*) ppObj, NULL);
57     else if (IsEqualGUID(riid, &IID_IStillImageA))
58         return StiCreateInstanceA(GetCurrentProcess(), STI_VERSION_REAL, (PSTIA*) ppObj, NULL);
59     else
60     {
61         FIXME("no interface %s\n", debugstr_guid(riid));
62         return E_NOINTERFACE;
63     }
64 }
65
66 static HRESULT WINAPI sti_cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
67 {
68     if (IsEqualGUID(riid, &IID_IUnknown) ||
69         IsEqualGUID(riid, &IID_IClassFactory))
70     {
71         IClassFactory_AddRef( iface );
72         *ppobj = iface;
73         return S_OK;
74     }
75     FIXME("interface %s not implemented\n", debugstr_guid(riid));
76     return E_NOINTERFACE;
77 }
78
79 static ULONG WINAPI sti_cf_AddRef( IClassFactory *iface )
80 {
81     return 2;
82 }
83
84 static ULONG WINAPI sti_cf_Release( IClassFactory *iface )
85 {
86     return 1;
87 }
88
89 static HRESULT WINAPI sti_cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
90                                              REFIID riid, LPVOID *ppobj )
91 {
92     sti_cf *This = impl_from_IClassFactory( iface );
93     HRESULT r;
94     IUnknown *punk;
95
96     TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj);
97
98     *ppobj = NULL;
99
100     r = This->pfnCreateInstance( riid, pOuter, (LPVOID *)&punk );
101     if (FAILED(r))
102         return r;
103
104     r = IUnknown_QueryInterface( punk, riid, ppobj );
105     if (FAILED(r))
106         return r;
107
108     IUnknown_Release( punk );
109     return r;
110 }
111
112 static HRESULT WINAPI sti_cf_LockServer( IClassFactory *iface, BOOL dolock )
113 {
114     FIXME("(%p)->(%d)\n", iface, dolock);
115     return S_OK;
116 }
117
118 static const struct IClassFactoryVtbl sti_cf_vtbl =
119 {
120     sti_cf_QueryInterface,
121     sti_cf_AddRef,
122     sti_cf_Release,
123     sti_cf_CreateInstance,
124     sti_cf_LockServer
125 };
126
127 static sti_cf the_sti_cf = { &sti_cf_vtbl, sti_create };
128
129 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
130 {
131     TRACE("(0x%p, %d, %p)\n",hInstDLL,fdwReason,lpvReserved);
132
133     switch(fdwReason) {
134         case DLL_WINE_PREATTACH:
135             return FALSE;
136         case DLL_PROCESS_ATTACH:
137             DisableThreadLibraryCalls(hInstDLL);
138             break;
139         case DLL_PROCESS_DETACH:
140             break;
141     }
142     return TRUE;
143 }
144
145 /******************************************************************************
146  *           DllGetClassObject   (STI.@)
147  */
148 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
149 {
150     IClassFactory *cf = NULL;
151
152     TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
153
154     if (IsEqualGUID( rclsid, &CLSID_Sti ))
155     {
156        cf = (IClassFactory *)&the_sti_cf.vtbl;
157     }
158
159     if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
160     return IClassFactory_QueryInterface( cf, iid, ppv );
161 }
162
163 /******************************************************************************
164  *           DllCanUnloadNow   (STI.@)
165  */
166 HRESULT WINAPI DllCanUnloadNow( void )
167 {
168     FIXME("\n");
169     return S_FALSE;
170 }