Merge pull request #1632 from bbowyersmyth/StringStartsWith
[platform/upstream/coreclr.git] / src / utilcode / dlwrap.cpp
1 //
2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 //
5
6
7 #include "stdafx.h"                     // Precompiled header key.
8 #include "utilcode.h"
9 #include "metadata.h"
10 #include "ex.h"
11 #include "pedecoder.h"
12
13 #include <wininet.h>
14 #include <urlmon.h>
15 #include <version.h>
16
17 DWORD 
18 GetFileVersionInfoSizeW_NoThrow(
19         LPCWSTR lptstrFilename, /* Filename of version stamped file */
20         LPDWORD lpdwHandle
21         )
22 {
23     WRAPPER_NO_CONTRACT;
24     HRESULT hr=S_OK;
25     DWORD dwRet=0;
26     EX_TRY
27     {
28         dwRet=GetFileVersionInfoSize( (LPWSTR)lptstrFilename,  lpdwHandle );  
29     }
30     EX_CATCH_HRESULT(hr);
31     if (hr!=S_OK)
32         SetLastError(hr);
33     return dwRet;
34     
35 }
36
37 BOOL
38 GetFileVersionInfoW_NoThrow(
39         LPCWSTR lptstrFilename, /* Filename of version stamped file */
40         DWORD dwHandle,         /* Information from GetFileVersionSize */
41         DWORD dwLen,            /* Length of buffer for info */
42         LPVOID lpData
43         )         
44 {
45     WRAPPER_NO_CONTRACT;
46     HRESULT hr=S_OK;
47     BOOL bRet=FALSE;
48     EX_TRY
49     {
50         bRet=GetFileVersionInfo( (LPWSTR)lptstrFilename, dwHandle,dwLen,lpData );  
51     }
52     EX_CATCH_HRESULT(hr);
53     if (hr!=S_OK)
54         SetLastError(hr);
55     return bRet;
56     
57 }
58
59 BOOL
60 VerQueryValueW_NoThrow(
61         const LPVOID pBlock,
62         LPCWSTR lpSubBlock,
63         LPVOID * lplpBuffer,
64         PUINT puLen
65         )     
66 {
67     WRAPPER_NO_CONTRACT;
68     HRESULT hr=S_OK;
69     BOOL bRet=FALSE;
70     EX_TRY
71     {
72         bRet=VerQueryValueW( pBlock, (LPWSTR)lpSubBlock,lplpBuffer,puLen );
73     }
74     EX_CATCH_HRESULT(hr);
75     if (hr!=S_OK)
76         SetLastError(hr);
77     return bRet;
78     
79 }
80
81 #if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE)
82 // The following functions are not used in CoreCLR. Normally LINKER can remove these functions
83 // from generated files.  But LINKER does it in two steps:
84 // 1. If no function in a source file is used, the file is ignored by LINKER
85 // 2. If one function is used, LINKER will first make sure all imported functions in the file
86 //    is available, and then it will remove unused functions.
87 // Instead of specifying all libs for imported functions needed by the following codes, we just
88 // remove them from compiling phase.
89 __success(return)
90 BOOL 
91 CreateUrlCacheEntryW_NoThrow(
92         IN LPCWSTR lpszUrlName,
93         IN DWORD dwExpectedFileSize,
94         IN LPCWSTR lpszFileExtension,
95         __out_ecount(MAX_LONGPATH+1) LPWSTR lpszFileName,
96         IN DWORD dwReserved
97         )
98 {
99     WRAPPER_NO_CONTRACT;
100     HRESULT hr=S_OK;
101     BOOL bRet=FALSE;
102     EX_TRY
103     {
104          bRet=CreateUrlCacheEntryW(lpszUrlName,dwExpectedFileSize,lpszFileExtension,
105                                                                 lpszFileName,dwReserved);
106     }
107     EX_CATCH_HRESULT(hr);
108     if (hr!=S_OK)
109         SetLastError(hr);
110     return bRet;
111     
112 }
113
114 BOOL  
115 CommitUrlCacheEntryW_NoThrow(
116         IN LPCWSTR lpszUrlName,
117         IN LPCWSTR lpszLocalFileName,
118         IN FILETIME ExpireTime,
119         IN FILETIME LastModifiedTime,
120         IN DWORD CacheEntryType,
121         IN LPCWSTR lpHeaderInfo,
122         IN DWORD dwHeaderSize,
123         IN LPCWSTR lpszFileExtension,
124         IN LPCWSTR lpszOriginalUrl
125         )
126 {
127     WRAPPER_NO_CONTRACT;
128     HRESULT hr=S_OK;
129     BOOL bRet=FALSE;
130     EX_TRY
131     {
132          bRet=CommitUrlCacheEntryW(lpszUrlName,lpszLocalFileName,ExpireTime,
133                                                         LastModifiedTime,CacheEntryType,(LPWSTR)lpHeaderInfo,
134                                                         dwHeaderSize,lpszFileExtension,lpszOriginalUrl);
135     }
136     EX_CATCH_HRESULT(hr);
137     if (hr!=S_OK)
138         SetLastError(hr);
139     return bRet;
140     
141 }
142
143 BOOL 
144 InternetTimeToSystemTimeA_NoThrow(
145         IN  LPCSTR lpszTime,         // NULL terminated string
146         OUT SYSTEMTIME *pst,         // output in GMT time
147         IN  DWORD dwReserved
148         ) 
149 {
150     WRAPPER_NO_CONTRACT;
151     HRESULT hr=S_OK;
152     BOOL bRet=FALSE;
153     EX_TRY
154     {
155          bRet=InternetTimeToSystemTimeA(lpszTime,pst,dwReserved); 
156     }
157     EX_CATCH_HRESULT(hr);
158     if (hr!=S_OK)
159         SetLastError(hr);
160     return bRet;
161     
162 }
163
164 HRESULT 
165 CoInternetCreateSecurityManager_NoThrow(
166         IServiceProvider *pSP,
167         IInternetSecurityManager **ppSM, 
168         DWORD dwReserved
169         )
170 {
171     WRAPPER_NO_CONTRACT;
172     HRESULT hr=S_OK;
173     EX_TRY
174     {
175          hr=CoInternetCreateSecurityManager(pSP,ppSM, dwReserved);
176     }
177     EX_CATCH_HRESULT(hr);
178     return hr;
179 }
180
181 HRESULT 
182 URLDownloadToCacheFileW_NoThrow(
183         LPUNKNOWN lpUnkcaller,
184         LPCWSTR szURL,
185         __out_ecount(dwBufLength) LPWSTR szFileName,
186         DWORD dwBufLength,
187         DWORD dwReserved,
188         IBindStatusCallback *pBSC
189         )
190 {
191     WRAPPER_NO_CONTRACT;
192     HRESULT hr=S_OK;
193     EX_TRY
194     {
195          hr=URLDownloadToCacheFileW(lpUnkcaller,szURL,szFileName,dwBufLength,dwReserved,pBSC);
196     }
197     EX_CATCH_HRESULT(hr);
198     return hr;
199 }
200
201 HRESULT 
202 CoInternetGetSession_NoThrow(
203         WORD dwSessionMode,
204         IInternetSession **ppIInternetSession,
205         DWORD dwReserved
206         )
207 {
208    WRAPPER_NO_CONTRACT;
209     HRESULT hr=S_OK;
210     EX_TRY
211     {
212          hr=CoInternetGetSession(dwSessionMode,ppIInternetSession,dwReserved);
213     }
214     EX_CATCH_HRESULT(hr);
215     return hr;
216 }
217
218 HRESULT 
219 CopyBindInfo_NoThrow( 
220         const BINDINFO * pcbiSrc, BINDINFO * pbiDest
221         )
222 {
223    WRAPPER_NO_CONTRACT;
224     HRESULT hr=S_OK;
225     EX_TRY
226     {
227          hr=CopyBindInfo(pcbiSrc,pbiDest );
228     }
229     EX_CATCH_HRESULT(hr);
230     return hr;
231 }
232 #endif // FEATURE_CORECLR && !CROSSGEN_COMPILE