The right type for handles in C interfaces

后端 未结 4 764
名媛妹妹
名媛妹妹 2020-12-29 08:11

I\'m creating a C api that hides some functionality in a DLL file.

Since everything is C++ on the inside most of the functions works against handles which maps direc

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 08:55

    If you look at how Microsoft defines it's winapi handles (winnt.h) it actually looks like this:

    struct HWND__ { int unused; }; typedef struct HWND__ *HWND
    

    in fact they have a macro for this:

    #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
    

    so.. this seems to be a common practice to do so. Unfortunately I can't make another suggestion except this one, which you already mentioned, but I hope it helps you anyway.

提交回复
热议问题