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.
4
5 // Various inline functions and macros to fix compilation of 32 bit target
6 // on MSVC with /Wp64 flag enabled.
7
8 #ifndef BASE_FIX_WP64_H__
9 #define BASE_FIX_WP64_H__
10 #pragma once
11
12 #include <windows.h>
13
14 // Platform SDK fixes when building with /Wp64 for a 32 bits target.
15 #if !defined(_WIN64) && defined(_Wp64)
16
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.
InterlockedExchangePointer(void * volatile * target,void * value)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)))));
26 }
27 #endif // #ifdef InterlockedExchangePointer
28
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.
SetWindowLongPtrA(HWND window,int index,LONG_PTR new_long)34 inline LONG_PTR SetWindowLongPtrA(HWND window, int index, LONG_PTR new_long) {
35 return ::SetWindowLongA(window, index, static_cast<LONG>(new_long));
36 }
37 #endif // #ifdef SetWindowLongPtrA
38
39 #ifdef SetWindowLongPtrW
40 #undef SetWindowLongPtrW
SetWindowLongPtrW(HWND window,int index,LONG_PTR new_long)41 inline LONG_PTR SetWindowLongPtrW(HWND window, int index, LONG_PTR new_long) {
42 return ::SetWindowLongW(window, index, static_cast<LONG>(new_long));
43 }
44 #endif // #ifdef SetWindowLongPtrW
45
46 #ifdef GetWindowLongPtrA
47 #undef GetWindowLongPtrA
GetWindowLongPtrA(HWND window,int index)48 inline LONG_PTR GetWindowLongPtrA(HWND window, int index) {
49 return ::GetWindowLongA(window, index);
50 }
51 #endif // #ifdef GetWindowLongPtrA
52
53 #ifdef GetWindowLongPtrW
54 #undef GetWindowLongPtrW
GetWindowLongPtrW(HWND window,int index)55 inline LONG_PTR GetWindowLongPtrW(HWND window, int index) {
56 return ::GetWindowLongW(window, index);
57 }
58 #endif // #ifdef GetWindowLongPtrW
59
60 #ifdef SetClassLongPtrA
61 #undef SetClassLongPtrA
SetClassLongPtrA(HWND window,int index,LONG_PTR new_long)62 inline LONG_PTR SetClassLongPtrA(HWND window, int index, LONG_PTR new_long) {
63 return ::SetClassLongA(window, index, static_cast<LONG>(new_long));
64 }
65 #endif // #ifdef SetClassLongPtrA
66
67 #ifdef SetClassLongPtrW
68 #undef SetClassLongPtrW
SetClassLongPtrW(HWND window,int index,LONG_PTR new_long)69 inline LONG_PTR SetClassLongPtrW(HWND window, int index, LONG_PTR new_long) {
70 return ::SetClassLongW(window, index, static_cast<LONG>(new_long));
71 }
72 #endif // #ifdef SetClassLongPtrW
73
74 #endif // #if !defined(_WIN64) && defined(_Wp64)
75
76 #endif // BASE_FIX_WP64_H__
77