COM interface and returning the structs (C++)

I keep thinking about how best to implement the interaction between a shared (DLL) library and an application in C++. I settled on the idea of ​​a COM interface. The essence of this idea is that we have purely virtual classes (interfaces) in header files:

class INode
{
public:
    virtual ~INode() = default;
    virtual ENodeType type() = 0;
    virtual void set_name(const char* name_str) noexcept = 0;
    [[nodiscard]] virtual const char* name() noexcept = 0;
    [[nodiscard]] virtual INode* parent() noexcept = 0;
    [[nodiscard]] virtual INode* children() noexcept = 0;
    [[nodiscard]] virtual unsigned children_count() noexcept = 0;
    virtual EResultCode add_child(INode* node) noexcept = 0;
    virtual EResultCode remove_child(INode* node) noexcept = 0;
};

But they are not exported from the library directly, only some functions are exported (in pure C style), which create real objects inside the library and simply return a pointer (of interface type) to this created object:

extern "C"
{
    LIB_API INode* create_node();
    LIB_API void destroy_node(const INode* node);
}

As a result, the user (of lib) only deals with pointers to objects. This way we don’t need to export classes and at the same time OOP seems to work.

But my goal is to ensure that only information about what architecture the library was compiled on (x86 or x64) would be enough for its reliable use, regardless of the compiler (let’s say the library was compiled by one compiler for x86, but it can be used in application compiled by another compiler for x86)

But several questions arise.

  • Is there any guarantee in C++ that standard types (int, float, char*, etc.) will always (in all compilers) be the same size for the same architecture? Is there some way to guarantee this?
  • In the case of a COM interface, is it a good idea to return (and pass as an argument to methods) structures? Let’s say I have a structure declared somewhere in the headers (consisting of fields of these standard types), and on the library side the method returns it. Even if I achieve a guarantee that all the fields of the structure will be the same types in any compilers, are there any pitfalls here (like “in compiler A, these structures are packed in one order, and in compiler B – in another + some alignment). I can, of course, return references or pointers to these structures, but this does not change the essence (it is still important how exactly the bytes are located in the structure).

I tried returning structures, and even types from the standard library (such as std::vector), it worked (on same compiler & cpp standard), but the question is – will it always work? I would like to understand what is worth doing and what is not, and what options there are.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật