urlmon: Added video/mpeg mime filter.
[wine] / dlls / urlmon / urlmon_main.c
1 /*
2  * UrlMon
3  *
4  * Copyright (c) 2000 Patrik Stridvall
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 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28
29 #define NO_SHLWAPI_REG
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "winuser.h"
35 #include "urlmon.h"
36 #include "urlmon_main.h"
37 #include "ole2.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
40
41 LONG URLMON_refCount = 0;
42
43 HINSTANCE URLMON_hInstance = 0;
44 static HMODULE hCabinet = NULL;
45
46 static void init_session(BOOL);
47
48 /***********************************************************************
49  *              DllMain (URLMON.init)
50  */
51 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
52 {
53     TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
54
55     switch(fdwReason) {
56     case DLL_PROCESS_ATTACH:
57         DisableThreadLibraryCalls(hinstDLL);
58         URLMON_hInstance = hinstDLL;
59         init_session(TRUE);
60         break;
61
62     case DLL_PROCESS_DETACH:
63         if (hCabinet)
64             FreeLibrary(hCabinet);
65         hCabinet = NULL;
66         init_session(FALSE);
67         URLMON_hInstance = 0;
68         break;
69     }
70     return TRUE;
71 }
72
73
74 /***********************************************************************
75  *              DllInstall (URLMON.@)
76  */
77 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
78 {
79   FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
80         debugstr_w(cmdline));
81
82   return S_OK;
83 }
84
85 /***********************************************************************
86  *              DllCanUnloadNow (URLMON.@)
87  */
88 HRESULT WINAPI DllCanUnloadNow(void)
89 {
90     return URLMON_refCount != 0 ? S_FALSE : S_OK;
91 }
92
93
94
95 /******************************************************************************
96  * Urlmon ClassFactory
97  */
98 typedef struct {
99     const IClassFactoryVtbl *lpClassFactoryVtbl;
100
101     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
102 } ClassFactory;
103
104 #define CLASSFACTORY(x)  ((IClassFactory*)  &(x)->lpClassFactoryVtbl)
105
106 static HRESULT WINAPI CF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppv)
107 {
108     *ppv = NULL;
109
110     if(IsEqualGUID(riid, &IID_IUnknown)) {
111         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
112         *ppv = iface;
113     }else if(IsEqualGUID(riid, &IID_IClassFactory)) {
114         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
115         *ppv = iface;
116     }
117
118     if(*ppv) {
119         IUnknown_AddRef((IUnknown*)*ppv);
120         return S_OK;
121     }
122
123     WARN("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ppv);
124     return E_NOINTERFACE;
125 }
126
127 static ULONG WINAPI CF_AddRef(IClassFactory *iface)
128 {
129     URLMON_LockModule();
130     return 2;
131 }
132
133 static ULONG WINAPI CF_Release(IClassFactory *iface)
134 {
135     URLMON_UnlockModule();
136     return 1;
137 }
138
139
140 static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
141                                         REFIID riid, LPVOID *ppobj)
142 {
143     ClassFactory *This = (ClassFactory*)iface;
144     HRESULT hres;
145     LPUNKNOWN punk;
146     
147     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
148
149     *ppobj = NULL;
150     if(SUCCEEDED(hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk))) {
151         hres = IUnknown_QueryInterface(punk, riid, ppobj);
152         IUnknown_Release(punk);
153     }
154     return hres;
155 }
156
157 static HRESULT WINAPI CF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
158 {
159     TRACE("(%d)\n", dolock);
160
161     if (dolock)
162            URLMON_LockModule();
163     else
164            URLMON_UnlockModule();
165
166     return S_OK;
167 }
168
169 static const IClassFactoryVtbl ClassFactoryVtbl =
170 {
171     CF_QueryInterface,
172     CF_AddRef,
173     CF_Release,
174     CF_CreateInstance,
175     CF_LockServer
176 };
177
178 static const ClassFactory FileProtocolCF =
179     { &ClassFactoryVtbl, FileProtocol_Construct};
180 static const ClassFactory FtpProtocolCF =
181     { &ClassFactoryVtbl, FtpProtocol_Construct};
182 static const ClassFactory HttpProtocolCF =
183     { &ClassFactoryVtbl, HttpProtocol_Construct};
184 static const ClassFactory SecurityManagerCF =
185     { &ClassFactoryVtbl, SecManagerImpl_Construct};
186 static const ClassFactory ZoneManagerCF =
187     { &ClassFactoryVtbl, ZoneMgrImpl_Construct};
188  
189 struct object_creation_info
190 {
191     const CLSID *clsid;
192     IClassFactory *cf;
193     LPCWSTR protocol;
194 };
195
196 static const WCHAR wszFile[] = {'f','i','l','e',0};
197 static const WCHAR wszFtp[]  = {'f','t','p',0};
198 static const WCHAR wszHttp[] = {'h','t','t','p',0};
199
200 static const struct object_creation_info object_creation[] =
201 {
202     { &CLSID_FileProtocol,            CLASSFACTORY(&FileProtocolCF),    wszFile },
203     { &CLSID_FtpProtocol,             CLASSFACTORY(&FtpProtocolCF),     wszFtp  },
204     { &CLSID_HttpProtocol,            CLASSFACTORY(&HttpProtocolCF),    wszHttp },
205     { &CLSID_InternetSecurityManager, CLASSFACTORY(&SecurityManagerCF), NULL    },
206     { &CLSID_InternetZoneManager,     CLASSFACTORY(&ZoneManagerCF),     NULL    }
207 };
208
209 static void init_session(BOOL init)
210 {
211     IInternetSession *session;
212     int i;
213
214     CoInternetGetSession(0, &session, 0);
215
216     for(i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++) {
217         if(object_creation[i].protocol) {
218             if(init)
219                 IInternetSession_RegisterNameSpace(session, object_creation[i].cf,
220                         object_creation[i].clsid, object_creation[i].protocol, 0, NULL, 0);
221             else
222                 IInternetSession_UnregisterNameSpace(session, object_creation[i].cf,
223                         object_creation[i].protocol);
224         }
225     }
226
227     IInternetSession_Release(session);
228 }
229
230 /*******************************************************************************
231  * DllGetClassObject [URLMON.@]
232  * Retrieves class object from a DLL object
233  *
234  * NOTES
235  *    Docs say returns STDAPI
236  *
237  * PARAMS
238  *    rclsid [I] CLSID for the class object
239  *    riid   [I] Reference to identifier of interface for class object
240  *    ppv    [O] Address of variable to receive interface pointer for riid
241  *
242  * RETURNS
243  *    Success: S_OK
244  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
245  *             E_UNEXPECTED
246  */
247
248 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
249 {
250     int i;
251     
252     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
253     
254     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
255     {
256         if (IsEqualGUID(object_creation[i].clsid, rclsid))
257             return IClassFactory_QueryInterface(object_creation[i].cf, riid, ppv);
258     }
259
260     FIXME("%s: no class found.\n", debugstr_guid(rclsid));
261     return CLASS_E_CLASSNOTAVAILABLE;
262 }
263
264
265 /***********************************************************************
266  *              DllRegisterServerEx (URLMON.@)
267  */
268 HRESULT WINAPI DllRegisterServerEx(void)
269 {
270     FIXME("(void): stub\n");
271
272     return E_FAIL;
273 }
274
275 /**************************************************************************
276  *                 UrlMkSetSessionOption (URLMON.@)
277  */
278 HRESULT WINAPI UrlMkSetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
279                                         DWORD Reserved)
280 {
281     FIXME("(%#x, %p, %#x): stub\n", dwOption, pBuffer, dwBufferLength);
282
283     return S_OK;
284 }
285
286 static const CHAR Agent[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
287
288 /**************************************************************************
289  *                 ObtainUserAgentString (URLMON.@)
290  */
291 HRESULT WINAPI ObtainUserAgentString(DWORD dwOption, LPSTR pcszUAOut, DWORD *cbSize)
292 {
293     FIXME("(%d, %p, %p): stub\n", dwOption, pcszUAOut, cbSize);
294
295     if(dwOption) {
296       ERR("dwOption: %d, must be zero\n", dwOption);
297     }
298
299     if (sizeof(Agent) < *cbSize)
300         *cbSize = sizeof(Agent);
301     lstrcpynA(pcszUAOut, Agent, *cbSize); 
302
303     return S_OK;
304 }
305
306 HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
307 {
308     TRACE("(%s,%s,%08x)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
309     return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags)==0?S_OK:S_FALSE;
310 }
311
312 /**************************************************************************
313  *                 IsValidURL (URLMON.@)
314  * 
315  * Determines if a specified string is a valid URL.
316  *
317  * PARAMS
318  *  pBC        [I] ignored, must be NULL.
319  *  szURL      [I] string that represents the URL in question.
320  *  dwReserved [I] reserved and must be zero.
321  *
322  * RETURNS
323  *  Success: S_OK.
324  *  Failure: S_FALSE.
325  *  returns E_INVALIDARG if one or more of the args is invalid.
326  *
327  * TODO:
328  *  test functionality against windows to see what a valid URL is.
329  */
330 HRESULT WINAPI IsValidURL(LPBC pBC, LPCWSTR szURL, DWORD dwReserved)
331 {
332     FIXME("(%p, %s, %d): stub\n", pBC, debugstr_w(szURL), dwReserved);
333     
334     if (pBC != NULL || dwReserved != 0)
335         return E_INVALIDARG;
336     
337     return S_OK;
338 }
339
340 /**************************************************************************
341  *                 FaultInIEFeature (URLMON.@)
342  *
343  *  Undocumented.  Appears to be used by native shdocvw.dll.
344  */
345 HRESULT WINAPI FaultInIEFeature( HWND hwnd, uCLSSPEC * pClassSpec,
346                                  QUERYCONTEXT *pQuery, DWORD flags )
347 {
348     FIXME("%p %p %p %08x\n", hwnd, pClassSpec, pQuery, flags);
349     return E_NOTIMPL;
350 }
351
352 /**************************************************************************
353  *                 CoGetClassObjectFromURL (URLMON.@)
354  */
355 HRESULT WINAPI CoGetClassObjectFromURL( REFCLSID rclsid, LPCWSTR szCodeURL, DWORD dwFileVersionMS,
356                                         DWORD dwFileVersionLS, LPCWSTR szContentType,
357                                         LPBINDCTX pBindCtx, DWORD dwClsContext, LPVOID pvReserved,
358                                         REFIID riid, LPVOID *ppv )
359 {
360     FIXME("(%s %s %d %d %s %p %d %p %s %p) Stub!\n", debugstr_guid(rclsid), debugstr_w(szCodeURL),
361         dwFileVersionMS, dwFileVersionLS, debugstr_w(szContentType), pBindCtx, dwClsContext, pvReserved,
362         debugstr_guid(riid), ppv);
363     return E_NOINTERFACE;
364 }
365
366 /***********************************************************************
367  *           ReleaseBindInfo (URLMON.@)
368  *
369  * Release the resources used by the specified BINDINFO structure.
370  *
371  * PARAMS
372  *  pbindinfo [I] BINDINFO to release.
373  *
374  * RETURNS
375  *  Nothing.
376  */
377 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
378 {
379     DWORD size;
380
381     TRACE("(%p)\n", pbindinfo);
382
383     if(!pbindinfo || !(size = pbindinfo->cbSize))
384         return;
385
386     CoTaskMemFree(pbindinfo->szExtraInfo);
387     ReleaseStgMedium(&pbindinfo->stgmedData);
388
389     if(offsetof(BINDINFO, szExtraInfo) < size)
390         CoTaskMemFree(pbindinfo->szCustomVerb);
391
392
393     if(pbindinfo->pUnk && offsetof(BINDINFO, pUnk) < size)
394         IUnknown_Release(pbindinfo->pUnk);
395
396     memset(pbindinfo, 0, size);
397     pbindinfo->cbSize = size;
398 }
399
400 /***********************************************************************
401  *           FindMimeFromData (URLMON.@)
402  *
403  * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
404  */
405 static BOOL text_html_filter(const BYTE const *b, DWORD size)
406 {
407     int i;
408
409     if(size < 5)
410         return FALSE;
411
412     for(i=0; i < size-5; i++) {
413         if(b[i] == '<'
414            && (b[i+1] == 'h' || b[i+1] == 'H')
415            && (b[i+2] == 't' || b[i+2] == 'T')
416            && (b[i+3] == 'm' || b[i+3] == 'M')
417            && (b[i+4] == 'l' || b[i+4] == 'L'))
418             return TRUE;
419     }
420
421     return FALSE;
422 }
423
424 static BOOL image_gif_filter(const BYTE const *b, DWORD size)
425 {
426     return size >= 6
427         && (b[0] == 'G' || b[0] == 'g')
428         && (b[1] == 'I' || b[1] == 'i')
429         && (b[2] == 'F' || b[2] == 'f')
430         &&  b[3] == '8'
431         && (b[4] == '7' || b[4] == '9')
432         && (b[5] == 'A' || b[5] == 'a');
433 }
434
435 static BOOL image_pjpeg_filter(const BYTE const *b, DWORD size)
436 {
437     return size > 2 && b[0] == 0xff && b[1] == 0xd8;
438 }
439
440 static BOOL image_tiff_filter(const BYTE const *b, DWORD size)
441 {
442     return size > 2 && b[0] == 0x4d && b[1] == 0x4d;
443 }
444
445 static BOOL image_xpng_filter(const BYTE const *b, DWORD size)
446 {
447     static const BYTE xpng_header[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a};
448     return size > sizeof(xpng_header) && !memcmp(b, xpng_header, sizeof(xpng_header));
449 }
450
451 static BOOL image_bmp_filter(const BYTE const *b, DWORD size)
452 {
453     return size >= 14
454         && b[0] == 0x42 && b[1] == 0x4d
455         && *(DWORD*)(b+6) == 0;
456 }
457
458 static BOOL video_avi_filter(const BYTE const *b, DWORD size)
459 {
460     return size > 12
461         && b[0] == 'R' && b[1] == 'I' && b[2] == 'F' && b[3] == 'F'
462         && b[8] == 'A' && b[9] == 'V' && b[10] == 'I' && b[11] == 0x20;
463 }
464
465 static BOOL video_mpeg_filter(const BYTE const *b, DWORD size)
466 {
467     return size > 4
468         && !b[0] && !b[1] && b[2] == 0x01
469         && (b[3] == 0xb3 || b[3] == 0xba);
470 }
471
472 static BOOL text_plain_filter(const BYTE const *b, DWORD size)
473 {
474     const BYTE *ptr;
475
476     for(ptr = b; ptr < b+size-1; ptr++) {
477         if(*ptr < 0x20 && *ptr != '\n' && *ptr != '\r' && *ptr != '\t')
478             return FALSE;
479     }
480
481     return TRUE;
482 }
483
484 static BOOL application_octet_stream_filter(const BYTE const *b, DWORD size)
485 {
486     return TRUE;
487 }
488
489 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
490         DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
491         LPWSTR* ppwzMimeOut, DWORD dwReserved)
492 {
493     TRACE("(%p,%s,%p,%d,%s,0x%x,%p,0x%x)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
494             debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
495
496     if(dwMimeFlags)
497         WARN("dwMimeFlags=%08x\n", dwMimeFlags);
498     if(dwReserved)
499         WARN("dwReserved=%d\n", dwReserved);
500
501     /* pBC seams to not be used */
502
503     if(!ppwzMimeOut || (!pwzUrl && !pBuffer))
504         return E_INVALIDARG;
505
506     if(pwzMimeProposed && (!pBuffer || (pBuffer && !cbSize))) {
507         DWORD len;
508
509         if(!pwzMimeProposed)
510             return E_FAIL;
511
512         len = strlenW(pwzMimeProposed)+1;
513         *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
514         memcpy(*ppwzMimeOut, pwzMimeProposed, len*sizeof(WCHAR));
515         return S_OK;
516     }
517
518     if(pBuffer) {
519         const BYTE const *buf = pBuffer;
520         DWORD len;
521         LPCWSTR ret = NULL;
522         int i;
523
524         static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
525         static const WCHAR wszImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
526         static const WCHAR wszImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
527         static const WCHAR wszImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
528         static const WCHAR wszImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
529         static const WCHAR wszImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
530         static const WCHAR wszVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
531         static const WCHAR wszVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
532         static const WCHAR wszTextPlain[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
533         static const WCHAR wszAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
534             'o','c','t','e','t','-','s','t','r','e','a','m','\0'};
535
536         static const struct {
537             LPCWSTR mime;
538             BOOL (*filter)(const BYTE const*,DWORD);
539         } mime_filters[] = {
540             {wszTextHtml,       text_html_filter},
541             {wszImageGif,       image_gif_filter},
542             {wszImagePjpeg,     image_pjpeg_filter},
543             {wszImageTiff,      image_tiff_filter},
544             {wszImageXPng,      image_xpng_filter},
545             {wszImageBmp,       image_bmp_filter},
546             {wszVideoAvi,       video_avi_filter},
547             {wszVideoMpeg,      video_mpeg_filter},
548             {wszTextPlain,      text_plain_filter},
549             {wszAppOctetStream, application_octet_stream_filter}
550         };
551
552         if(!cbSize)
553             return E_FAIL;
554
555         if(pwzMimeProposed && strcmpW(pwzMimeProposed, wszAppOctetStream)) {
556             for(i=0; i < sizeof(mime_filters)/sizeof(*mime_filters); i++) {
557                 if(!strcmpW(pwzMimeProposed, mime_filters[i].mime))
558                     break;
559             }
560
561             if(i == sizeof(mime_filters)/sizeof(*mime_filters)
562                     || mime_filters[i].filter(buf, cbSize)) {
563                 len = strlenW(pwzMimeProposed)+1;
564                 *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
565                 memcpy(*ppwzMimeOut, pwzMimeProposed, len*sizeof(WCHAR));
566                 return S_OK;
567             }
568         }
569
570         i=0;
571         while(!ret) {
572             if(mime_filters[i].filter(buf, cbSize))
573                 ret = mime_filters[i].mime;
574             i++;
575         }
576
577         TRACE("found %s for data\n"
578               "%02x %02x %02x %02x  %02x %02x %02x %02x  %02x %02x %02x %02x  %02x %02x %02x %02x\n",
579               debugstr_w(ret), buf[0],buf[1],buf[2],buf[3], buf[4],buf[5],buf[6],buf[7],
580               buf[8],buf[9],buf[10],buf[11], buf[12],buf[13],buf[14],buf[15]);
581
582         if(pwzMimeProposed) {
583             if(i == sizeof(mime_filters)/sizeof(*mime_filters))
584                 ret = pwzMimeProposed;
585
586             /* text/html is a special case */
587             if(!strcmpW(pwzMimeProposed, wszTextHtml) && !strcmpW(ret, wszTextPlain))
588                 ret = wszTextHtml;
589         }
590
591         len = strlenW(ret)+1;
592         *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
593         memcpy(*ppwzMimeOut, ret, len*sizeof(WCHAR));
594         return S_OK;
595     }
596
597     if(pwzUrl) {
598         HKEY hkey;
599         DWORD res, size;
600         LPCWSTR ptr;
601         WCHAR mime[64];
602
603         static const WCHAR wszContentType[] =
604                 {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
605
606         ptr = strrchrW(pwzUrl, '.');
607         if(!ptr)
608             return E_FAIL;
609
610         res = RegOpenKeyW(HKEY_CLASSES_ROOT, ptr, &hkey);
611         if(res != ERROR_SUCCESS)
612             return E_FAIL;
613
614         size = sizeof(mime);
615         res = RegQueryValueExW(hkey, wszContentType, NULL, NULL, (LPBYTE)mime, &size);
616         RegCloseKey(hkey);
617         if(res != ERROR_SUCCESS)
618             return E_FAIL;
619
620         *ppwzMimeOut = CoTaskMemAlloc(size);
621         memcpy(*ppwzMimeOut, mime, size);
622         return S_OK;
623     }
624
625     return E_FAIL;
626 }
627
628 /***********************************************************************
629  * Extract (URLMON.@)
630  */
631 HRESULT WINAPI Extract(void *dest, LPCSTR szCabName)
632 {
633     HRESULT (WINAPI *pExtract)(void *, LPCSTR);
634
635     if (!hCabinet)
636         hCabinet = LoadLibraryA("cabinet.dll");
637
638     if (!hCabinet) return HRESULT_FROM_WIN32(GetLastError());
639     pExtract = (void *)GetProcAddress(hCabinet, "Extract");
640     if (!pExtract) return HRESULT_FROM_WIN32(GetLastError());
641
642     return pExtract(dest, szCabName);
643 }