Replace MAX_PATH with new defines, rest of coreclr.
[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 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