How to expose STL list over DLL boundary?

后端 未结 3 800
情话喂你
情话喂你 2021-02-02 02:42

I have a DLL which needs to access data stored in STL containers in the host application. Because C++ has no standard ABI, and I want to support different compilers, the interf

3条回答
  •  没有蜡笔的小新
    2021-02-02 03:38

    Perhaps you can pass something like "handles" to list/deque iterators? These handle types would be opaque and declared in a header file you would ship to the users. Internally, you would need to map the handle values to list/deque iterators. Basically, the user would write code like:

    ListHandle lhi = GetListDataBegin();
    const ListHandle lhe = GetListDataEnd();
    
    while (lhi != lhe)
    {
      int value = GetListItem(lhi);
      ...
      lhi = GetNextListItem(lhi);
    }
    

提交回复
热议问题