dtolnay/cxx

Adding windows pointer/integer data types

Open

#254 opened on Aug 15, 2020

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Rust (253 forks)batch import
help wantedwindows

Repository metrics

Stars
 (4,472 stars)
PR merge metrics
 (Avg merge 8m) (3 merged PRs in 30d)

Description

I have been trying to access a 3rd-party win32 API using cxx. One of the first things I am coming across is that the library contains extensive use of windows-specific type aliases like DWORD, WPARAM, LPARAM, HINSTANCE etc. most of which are equivalent to an unsigned integer of some size (u32 in case of 32-bit windows). Now obviously, since cxx is unaware of this, I am unable to pass or return these by value.

If I try to use u32 inside of the extern "C" block, I get errors like:

lib.rs.cc(10): error C2440: 'initializing': cannot convert from 'DWORD (__thiscall MyClass::* )(DWORD)' to 'uint32_t (__thiscall MyClass:
:* )(uint32_t)'
lib.rs.cc(10): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
exit code: 2

Is there any workaround to this to make cxx "aware" of that these types are interchangeable with unsigned integers? I believe most of these are defined in minwindef.h in the windows SDK.

Contributor guide