通过 COM 互操作将 C# 字典编组到 C++
有没有一种通过 COM 互操作编组 Dictionary
的好方法?
到目前为止的想法包括将每个KeyPair
标记为一个可以编组为SafeArray
的字符串数组,或者拥有两个包含键和值的字符串数组。
两者似乎都不是特别令人满意。有什么想法吗?
Is there a good way of marshalling a Dictionary<string, string>
over COM interop?
Ideas so far include tokenising each KeyPair
to an array of strings which can be marshalled as a SafeArray
, or having two string arrays containing keys and values.
Neither seems particularly satisfactory. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您是否会找到一个非常优雅的解决方案,因为与非平凡托管类型的 COM 互操作总是会涉及自定义代码。
由于接收方 COM 客户端必须了解数据的语义,因此您可以将其编组到单个 SafeArray,其条目为 Key1、Value1、Key2、Value2 等。也许这只是您上面描述的第一个选项的重述?
I doubt you will find a very elegant solution, since COM interop with non-trivial managed types is always going to involve custom code.
Since your recipient COM client has to know the semantics of the data, you could just marshal to a single SafeArray whose entries are Key1, Value1, Key2, Value2, and so on. Maybe that's just a restatement of the first option you described above, though?