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// FusionHelpers.hpp
7//
8// Defines various legacy fusion types
9//
10// ============================================================
11
12#ifndef __FUSION_HELPERS_HPP__
13#define __FUSION_HELPERS_HPP__
14
15#include "clrtypes.h"
16#include "sstring.h"
17
18#include "clrhost.h"
19#include "shlwapi.h"
20#include "winwrap.h"
21#include "ex.h"
22#include "fusion.h"
23
24
25#include "peinformation.h"
26
27#define FUSION_NEW_SINGLETON(_type) new (nothrow) _type
28#define FUSION_NEW_ARRAY(_type, _n) new (nothrow) _type[_n]
29#define FUSION_DELETE_ARRAY(_ptr) if((_ptr)) delete [] (_ptr)
30#define FUSION_DELETE_SINGLETON(_ptr) if((_ptr)) delete (_ptr)
31
32#define SAFEDELETE(p) if ((p) != NULL) { FUSION_DELETE_SINGLETON((p)); (p) = NULL; };
33#define SAFEDELETEARRAY(p) if ((p) != NULL) { FUSION_DELETE_ARRAY((p)); (p) = NULL; };
34#define SAFERELEASE(p) if ((p) != NULL) { (p)->Release(); (p) = NULL; };
35
36#ifndef NEW
37#define NEW(_type) FUSION_NEW_SINGLETON(_type)
38#endif // !NEW
39
40#ifndef ARRAYSIZE
41#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
42#endif // !ARRAYSIZE
43
44#define MAX_VERSION_DISPLAY_SIZE sizeof("65535.65535.65535.65535")
45
46#define ASM_DISPLAYF_DEFAULT (ASM_DISPLAYF_VERSION \
47 |ASM_DISPLAYF_CULTURE \
48 |ASM_DISPLAYF_PUBLIC_KEY_TOKEN \
49 |ASM_DISPLAYF_RETARGET)
50
51#define SIGNATURE_BLOB_LENGTH 0x80
52#define SIGNATURE_BLOB_LENGTH_HASH 0x14
53#define MVID_LENGTH sizeof(GUID)
54
55#define PUBLIC_KEY_TOKEN_LEN 8
56
57inline
58WCHAR*
59WSTRDupDynamic(LPCWSTR pwszSrc)
60{
61 LPWSTR pwszDest = NULL;
62 if (pwszSrc != NULL)
63 {
64 const size_t dwLen = wcslen(pwszSrc) + 1;
65 pwszDest = FUSION_NEW_ARRAY(WCHAR, dwLen);
66
67 if( pwszDest )
68 memcpy(pwszDest, pwszSrc, dwLen * sizeof(WCHAR));
69 }
70
71 return pwszDest;
72}
73
74#define MAX_URL_LENGTH 2084 // same as INTERNET_MAX_URL_LENGTH
75
76// bit mask macro helpers
77#define MAX_ID_FROM_MASK(size) ((size) << 3)
78#define MASK_SIZE_FROM_ID(id) ((id) >> 3)
79#define IS_IN_RANGE(id, size) ((id) <= ((size) << 3))
80#define IS_BIT_SET(id, mask) (mask[((id)-1)>>3] & (0x1 << (((id)-1)&0x7)))
81#define SET_BIT(id, mask) (mask[((id)-1)>>3] |= (0x1<< (((id)-1)&0x7)))
82#define UNSET_BIT(id, mask) (mask[((id)-1)>>3] &= (0xFF - (0x1<<(((id)-1)&0x7))))
83
84int FusionCompareStringI(LPCWSTR pwz1, LPCWSTR pwz2);
85
86// CLR lobal culture ID
87extern LocaleID g_lcid;
88
89#endif
90