Emit handles as void* not IntPtr
riverar opened this issue · comments
Rust currently emits isize/usize
integers as a result of decomposing our synthetic handle types and encountering IntPtr/UIntPtr
. Rust would now like to emit pointers to better align with its core handle type, but it cannot differentiate between legitimate pointer-sized integers (e.g. LRESULT
) and handles (e.g. HMODULE
).
The proposed change is to emit all handles with their original pointer type.
// Before
public struct HMODULE
{
public IntPtr Value;
}
// After
public struct HMODULE
{
public unsafe void* Value;
}
See also: microsoft/windows-rs#3093
This is substantiated by the fact that wtypes.h
, and many others, actually defines these as pointers so this is just asking that the metadata is faithful to the original definitions, for example:
typedef void * HANDLE;
typedef void *HMODULE;
typedef void *HINSTANCE;
typedef void *HTASK;
typedef void *HKEY;
typedef void *HDESK;
typedef void *HMF;
typedef void *HEMF;
typedef void *HPEN;
typedef void *HRSRC;
typedef void *HSTR;
typedef void *HWINSTA;
typedef void *HKL;
typedef void *HGDIOBJ;
These and others are declared with the DECLARE_HANDLE
macro. Should all of these be void*
?
Yes, the underlying handle type for DECLARE_HANDLE
are all pointers and void*
is the generic underlying type for such handles.