dtolnay/cxx

Adding windows pointer/integer data types

Ouverte

#254 ouverte le 15 août 2020

 (6 commentaires) (0 réaction) (0 personne assignée)Rust (253 forks)batch import
help wantedwindows

Métriques du dépôt

Stars
 (4 472 étoiles)
Métriques de merge PR
 (Merge moyen 8m) (3 PRs mergées en 30 j)

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.

Guide contributeur