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