dtolnay/cxx

Adding windows pointer/integer data types

オープン

#254 opened on 2020/08/15

 (6 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (253 件のフォーク)batch import
help wantedwindows

Repository metrics

Stars
 (4,472 個のスター)
PR merge metrics
 (平均マージ 8m) (30d で 3 merged PRs)

説明

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.

コントリビューターガイド