NO

Author Topic: __ptr32 & __ptr64 keyword bug in Pelles C  (Read 3451 times)

Jacky

  • Guest
__ptr32 & __ptr64 keyword bug in Pelles C
« on: April 06, 2016, 05:52:24 AM »
See this code snippet:
Code: [Select]
printf("POINTER: %u\n", sizeof(void *));
printf("POINTER_32: %u\n", sizeof(void *POINTER_32)); // or: void *__ptr32
printf("POINTER_64: %u\n", sizeof(void *POINTER_64)); // or: void *__ptr64
Compiled with Pelles C, it prints 4, 4, 4 (x86) or 8, 8, 8 (x64).
Compiled with Microsoft C++, it prints 4, 4, 8 (x86) or 8, 4, 8 (x64).

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: __ptr32 & __ptr64 keyword bug in Pelles C
« Reply #1 on: April 06, 2016, 10:30:12 AM »
Quote
__ptr32, __ptr64

Visual Studio 2015 Other Versions
 
Microsoft Specific
__ptr32 represents a native pointer on a 32-bit system, while __ptr64 represents a native pointer on a 64-bit system.
The following example shows how to declare each of these pointer types:
int * __ptr32 p32;
int * __ptr64 p64;
On a 32-bit system, a pointer declared with __ptr64 is truncated to a 32-bit pointer. On a 64-bit system, a pointer declared with __ptr32 is coerced to a 64-bit pointer.
???
« Last Edit: April 06, 2016, 11:10:24 AM by TimoVJL »
May the source be with you

Jacky

  • Guest
Re: __ptr32 & __ptr64 keyword bug in Pelles C
« Reply #2 on: April 08, 2016, 11:52:23 AM »
Quote
__ptr32, __ptr64

Visual Studio 2015 Other Versions
 
Microsoft Specific
__ptr32 represents a native pointer on a 32-bit system, while __ptr64 represents a native pointer on a 64-bit system.
The following example shows how to declare each of these pointer types:
int * __ptr32 p32;
int * __ptr64 p64;
On a 32-bit system, a pointer declared with __ptr64 is truncated to a 32-bit pointer. On a 64-bit system, a pointer declared with __ptr32 is coerced to a 64-bit pointer.
???
The case I'm using __ptr32 & __ptr64 may not be affected. Only one of theme are using always. I just need the size to pad the structure members to the correct offset for both 32-bit and 64-bit OS. Now I use LONG32 & LONG 64 instead TCHAR *__ptr32 & TCHAR *__ptr64.
Code: [Select]
typedef union {
struct {
UINT flags;
TCHAR *__ptr64 psz;
LONG32 lParam;
POINT pt;
UINT vkDirection;
} lvfi32;
struct {
UINT flags;
TCHAR *__ptr64 psz;
LONG64 lParam;
POINT pt;
UINT vkDirection;
} lvfi64;
} LV_FINDINFO;
Code: [Select]
LV_FINDINFO LVfi  = { 0 };
LV_FINDINFO *lpLVfi = (LV_FINDINFO *)VirtualAllocEx(hProcess, nullptr, sizeof(LV_FINDINFO), MEM_COMMIT, PAGE_READWRITE);
TCHAR *lpLVsz = (TCHAR *)VirtualAllocEx(hProcess, nullptr, sizeof(TCHAR) * 256, MEM_COMMIT, PAGE_READWRITE);
DWORD dwArch = GetProcessorArchitecture();
switch (dwArch) {
case PROCESSOR_ARCHITECTURE_INTEL:
    LVfi.LVfi32.flags = LVFI_STRING;
    LVfi.LVfi32.psz = lpLVsz;
    break;
case PROCESSOR_ARCHITECTURE_IA64:
case PROCESSOR_ARCHITECTURE_AMD64:
    LVfi.LVfi64.flags = LVFI_STRING;
    LVfi.LVfi64.psz = lpLVsz;
    break;
default:
    break;
}
WriteProcessMemory(hProcess, lpLVfi, &LVfi, sizeof(LV_FINDINFO), nullptr);
WriteProcessMemory(hProcess, lpLVsz, pszName, sizeof(TCHAR) * 256, nullptr);
SendMessage(hwndList, LVM_FINDITEM, (WPARAM)-1, (LPARAM)&lpLVfi->LVfi);
VirtualFreeEx(hProcess, lpLVsz, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, lpLVfi, 0, MEM_RELEASE);