oleaut32: Use a saner calling convention for the marshaller asm thunks.
[wine] / dlls / inetcomm / inetcomm_main.c
1 /*
2  * Internet Messaging APIs
3  *
4  * Copyright 2006 Robert Shearman for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnt.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "ocidl.h"
31 #include "rpcproxy.h"
32 #include "initguid.h"
33 #include "mimeole.h"
34
35 #include "inetcomm_private.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm);
40
41 static HINSTANCE instance;
42
43 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
44 {
45     static IMimeInternational *international;
46
47     TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
48
49     switch (fdwReason)
50     {
51     case DLL_WINE_PREATTACH:
52         return FALSE;
53     case DLL_PROCESS_ATTACH:
54         DisableThreadLibraryCalls(hinstDLL);
55         instance = hinstDLL;
56         if (!InternetTransport_RegisterClass(hinstDLL))
57             return FALSE;
58         MimeInternational_Construct(&international);
59         break;
60     case DLL_PROCESS_DETACH:
61         IMimeInternational_Release(international);
62         InternetTransport_UnregisterClass(hinstDLL);
63         break;
64     default:
65         break;
66     }
67     return TRUE;
68 }
69
70 /******************************************************************************
71  * ClassFactory
72  */
73 typedef struct
74 {
75     IClassFactory IClassFactory_iface;
76     HRESULT (*create_object)(IUnknown *, void **);
77 } cf;
78
79 static inline cf *impl_from_IClassFactory( IClassFactory *iface )
80 {
81     return CONTAINING_RECORD(iface, cf, IClassFactory_iface);
82 }
83
84 static HRESULT WINAPI cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
85 {
86     if (IsEqualGUID(riid, &IID_IUnknown) ||
87         IsEqualGUID(riid, &IID_IClassFactory))
88     {
89         IClassFactory_AddRef( iface );
90         *ppobj = iface;
91         return S_OK;
92     }
93
94     FIXME("interface %s not implemented\n", debugstr_guid(riid));
95     return E_NOINTERFACE;
96 }
97
98 static ULONG WINAPI cf_AddRef( IClassFactory *iface )
99 {
100     return 2;
101 }
102
103 static ULONG WINAPI cf_Release( IClassFactory *iface )
104 {
105     return 1;
106 }
107
108 static HRESULT WINAPI cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
109                                          REFIID riid, LPVOID *ppobj )
110 {
111     cf *This = impl_from_IClassFactory( iface );
112     HRESULT r;
113     IUnknown *punk;
114
115     TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
116
117     *ppobj = NULL;
118
119     r = This->create_object( pOuter, (LPVOID*) &punk );
120     if (FAILED(r))
121         return r;
122
123     r = IUnknown_QueryInterface( punk, riid, ppobj );
124     IUnknown_Release( punk );
125
126     return r;
127 }
128
129 static HRESULT WINAPI cf_LockServer( IClassFactory *iface, BOOL dolock)
130 {
131     FIXME("(%p)->(%d),stub!\n",iface,dolock);
132     return S_OK;
133 }
134
135 static const struct IClassFactoryVtbl cf_vtbl =
136 {
137     cf_QueryInterface,
138     cf_AddRef,
139     cf_Release,
140     cf_CreateInstance,
141     cf_LockServer
142 };
143
144 static cf mime_body_cf      = { { &cf_vtbl }, MimeBody_create };
145 static cf mime_allocator_cf = { { &cf_vtbl }, MimeAllocator_create };
146 static cf mime_message_cf   = { { &cf_vtbl }, MimeMessage_create };
147 static cf mime_security_cf  = { { &cf_vtbl }, MimeSecurity_create };
148 static cf virtual_stream_cf = { { &cf_vtbl }, VirtualStream_create };
149
150 /***********************************************************************
151  *              DllGetClassObject (INETCOMM.@)
152  */
153 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
154 {
155     IClassFactory *cf = NULL;
156
157     TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv );
158
159     if (IsEqualCLSID(rclsid, &CLSID_ISMTPTransport))
160         return SMTPTransportCF_Create(iid, ppv);
161
162     if (IsEqualCLSID(rclsid, &CLSID_ISMTPTransport2))
163         return SMTPTransportCF_Create(iid, ppv);
164
165     if (IsEqualCLSID(rclsid, &CLSID_IIMAPTransport))
166         return IMAPTransportCF_Create(iid, ppv);
167
168     if (IsEqualCLSID(rclsid, &CLSID_IPOP3Transport))
169         return POP3TransportCF_Create(iid, ppv);
170
171     if ( IsEqualCLSID( rclsid, &CLSID_IMimeSecurity ))
172     {
173         cf = &mime_security_cf.IClassFactory_iface;
174     }
175     else if( IsEqualCLSID( rclsid, &CLSID_IMimeMessage ))
176     {
177         cf = &mime_message_cf.IClassFactory_iface;
178     }
179     else if( IsEqualCLSID( rclsid, &CLSID_IMimeBody ))
180     {
181         cf = &mime_body_cf.IClassFactory_iface;
182     }
183     else if( IsEqualCLSID( rclsid, &CLSID_IMimeAllocator ))
184     {
185         cf = &mime_allocator_cf.IClassFactory_iface;
186     }
187     else if( IsEqualCLSID( rclsid, &CLSID_IVirtualStream ))
188     {
189         cf = &virtual_stream_cf.IClassFactory_iface;
190     }
191
192     if ( !cf )
193     {
194         FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
195         return CLASS_E_CLASSNOTAVAILABLE;
196     }
197
198     return IClassFactory_QueryInterface( cf, iid, ppv );
199 }
200
201 /***********************************************************************
202  *              DllCanUnloadNow (INETCOMM.@)
203  */
204 HRESULT WINAPI DllCanUnloadNow(void)
205 {
206     return S_FALSE;
207 }
208
209 /***********************************************************************
210  *              DllRegisterServer (INETCOMM.@)
211  */
212 HRESULT WINAPI DllRegisterServer(void)
213 {
214     return __wine_register_resources( instance );
215 }
216
217 /***********************************************************************
218  *              DllUnregisterServer (INETCOMM.@)
219  */
220 HRESULT WINAPI DllUnregisterServer(void)
221 {
222     return __wine_unregister_resources( instance );
223 }