• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include <windows.h>
12 
13 // Platform SDK fixes when building with /Wp64 for a 32 bits target.
14 #if !defined(_WIN64) && defined(_Wp64)
15 
16 #ifdef InterlockedExchangePointer
17 #undef InterlockedExchangePointer
18 // The problem is that the macro provided for InterlockedExchangePointer() is
19 // doing a (LONG) C-style cast that triggers invariably the warning C4312 when
20 // building on 32 bits.
InterlockedExchangePointer(void * volatile * target,void * value)21 inline void* InterlockedExchangePointer(void* volatile* target, void* value) {
22   return reinterpret_cast<void*>(static_cast<LONG_PTR>(InterlockedExchange(
23       reinterpret_cast<volatile LONG*>(target),
24       static_cast<LONG>(reinterpret_cast<LONG_PTR>(value)))));
25 }
26 #endif  // #ifdef InterlockedExchangePointer
27 
28 #ifdef SetWindowLongPtrA
29 #undef SetWindowLongPtrA
30 // When build on 32 bits, SetWindowLongPtrX() is a macro that redirects to
31 // SetWindowLongX(). The problem is that this function takes a LONG argument
32 // instead of a LONG_PTR.
SetWindowLongPtrA(HWND window,int index,LONG_PTR new_long)33 inline LONG_PTR SetWindowLongPtrA(HWND window, int index, LONG_PTR new_long) {
34   return ::SetWindowLongA(window, index, static_cast<LONG>(new_long));
35 }
36 #endif  // #ifdef SetWindowLongPtrA
37 
38 #ifdef SetWindowLongPtrW
39 #undef SetWindowLongPtrW
SetWindowLongPtrW(HWND window,int index,LONG_PTR new_long)40 inline LONG_PTR SetWindowLongPtrW(HWND window, int index, LONG_PTR new_long) {
41   return ::SetWindowLongW(window, index, static_cast<LONG>(new_long));
42 }
43 #endif  // #ifdef SetWindowLongPtrW
44 
45 #ifdef GetWindowLongPtrA
46 #undef GetWindowLongPtrA
GetWindowLongPtrA(HWND window,int index)47 inline LONG_PTR GetWindowLongPtrA(HWND window, int index) {
48   return ::GetWindowLongA(window, index);
49 }
50 #endif  // #ifdef GetWindowLongPtrA
51 
52 #ifdef GetWindowLongPtrW
53 #undef GetWindowLongPtrW
GetWindowLongPtrW(HWND window,int index)54 inline LONG_PTR GetWindowLongPtrW(HWND window, int index) {
55   return ::GetWindowLongW(window, index);
56 }
57 #endif  // #ifdef GetWindowLongPtrW
58 
59 #ifdef SetClassLongPtrA
60 #undef SetClassLongPtrA
SetClassLongPtrA(HWND window,int index,LONG_PTR new_long)61 inline LONG_PTR SetClassLongPtrA(HWND window, int index, LONG_PTR new_long) {
62   return ::SetClassLongA(window, index, static_cast<LONG>(new_long));
63 }
64 #endif  // #ifdef SetClassLongPtrA
65 
66 #ifdef SetClassLongPtrW
67 #undef SetClassLongPtrW
SetClassLongPtrW(HWND window,int index,LONG_PTR new_long)68 inline LONG_PTR SetClassLongPtrW(HWND window, int index, LONG_PTR new_long) {
69   return ::SetClassLongW(window, index, static_cast<LONG>(new_long));
70 }
71 #endif  // #ifdef SetClassLongPtrW
72 
73 #endif  // #if !defined(_WIN64) && defined(_Wp64)
74 
75 #endif  // BASE_FIX_WP64_H__
76