1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Various inline functions and macros to fix compilation of 32 bit target
6 // on MSVC with /Wp64 flag enabled.
8 #ifndef BASE_FIX_WP64_H__
9 #define BASE_FIX_WP64_H__
14 // Platform SDK fixes when building with /Wp64 for a 32 bits target.
15 #if !defined(_WIN64) && defined(_Wp64)
17 #ifdef InterlockedExchangePointer
18 #undef InterlockedExchangePointer
19 // The problem is that the macro provided for InterlockedExchangePointer() is
20 // doing a (LONG) C-style cast that triggers invariably the warning C4312 when
21 // building on 32 bits.
22 inline void* InterlockedExchangePointer(void* volatile* target
, void* value
) {
23 return reinterpret_cast<void*>(static_cast<LONG_PTR
>(InterlockedExchange(
24 reinterpret_cast<volatile LONG
*>(target
),
25 static_cast<LONG
>(reinterpret_cast<LONG_PTR
>(value
)))));
27 #endif // #ifdef InterlockedExchangePointer
29 #ifdef SetWindowLongPtrA
30 #undef SetWindowLongPtrA
31 // When build on 32 bits, SetWindowLongPtrX() is a macro that redirects to
32 // SetWindowLongX(). The problem is that this function takes a LONG argument
33 // instead of a LONG_PTR.
34 inline LONG_PTR
SetWindowLongPtrA(HWND window
, int index
, LONG_PTR new_long
) {
35 return ::SetWindowLongA(window
, index
, static_cast<LONG
>(new_long
));
37 #endif // #ifdef SetWindowLongPtrA
39 #ifdef SetWindowLongPtrW
40 #undef SetWindowLongPtrW
41 inline LONG_PTR
SetWindowLongPtrW(HWND window
, int index
, LONG_PTR new_long
) {
42 return ::SetWindowLongW(window
, index
, static_cast<LONG
>(new_long
));
44 #endif // #ifdef SetWindowLongPtrW
46 #ifdef GetWindowLongPtrA
47 #undef GetWindowLongPtrA
48 inline LONG_PTR
GetWindowLongPtrA(HWND window
, int index
) {
49 return ::GetWindowLongA(window
, index
);
51 #endif // #ifdef GetWindowLongPtrA
53 #ifdef GetWindowLongPtrW
54 #undef GetWindowLongPtrW
55 inline LONG_PTR
GetWindowLongPtrW(HWND window
, int index
) {
56 return ::GetWindowLongW(window
, index
);
58 #endif // #ifdef GetWindowLongPtrW
60 #ifdef SetClassLongPtrA
61 #undef SetClassLongPtrA
62 inline LONG_PTR
SetClassLongPtrA(HWND window
, int index
, LONG_PTR new_long
) {
63 return ::SetClassLongA(window
, index
, static_cast<LONG
>(new_long
));
65 #endif // #ifdef SetClassLongPtrA
67 #ifdef SetClassLongPtrW
68 #undef SetClassLongPtrW
69 inline LONG_PTR
SetClassLongPtrW(HWND window
, int index
, LONG_PTR new_long
) {
70 return ::SetClassLongW(window
, index
, static_cast<LONG
>(new_long
));
72 #endif // #ifdef SetClassLongPtrW
74 #endif // #if !defined(_WIN64) && defined(_Wp64)
76 #endif // BASE_FIX_WP64_H__