dtolnay/cxx

Adding windows pointer/integer data types

Aperta

#254 aperta il 15 ago 2020

 (6 commenti) (0 reazioni) (0 assegnatari)Rust (253 fork)batch import
help wantedwindows

Metriche repository

Star
 (4472 stelle)
Metriche merge PR
 (Merge medio 8m) (3 PR mergiate in 30 g)

Descrizione

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.

Guida contributor