.Net - Com PVariant 参数
我有点陷入一个奇怪的问题。我需要通过第 3 方 Active-X 类型库控制一些硬件。我的程序是用 C# 编写的。问题是一个 API / COM 调用需要对 PVariant 的引用 - 所以如果我正确地得到它,则需要一个指向 Variant 的指针。更糟糕的是,这只是一个大小不固定(元素计数)的 Varaint 数组的首地址。
问题是 - 除了这不是最佳实践 - 我没有机会改变该方法,也没有办法解决它。
有人曾经需要创建一个 COM 兼容的变体数组并将其起始地址传递给 COM 方法吗?这是怎么做到的?
我将不胜感激任何帮助!
谢谢先进的
Corelgott
I am a little stuck with a strange Problem. I need to control some Hardware via a 3rd Party Active-X typelibrary. My program is written in C#. The Problem is one API / COM call needs a ref to a PVariant - So if I get it correctly a Pointer to a Variant. To make things worse, this is just the first address of an Varaint Array with not fixed size (element count).
Problem is - beside this beeing not the best practice - I got no chance of changing that method and no way to working around it.
Anybody ever needed to create a COM compatible Variant-array and pass it's start address to a COM method? How is that done?
I'd appreciate any help on this!
Thx in advanced
Corelgott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 System.Runtime.InteropServices.Marshal .GetNativeVariantForObject?
另外,现在我回忆了一下,变体数组 (VT_ARRAY) 实际上是 SAFEARRAY 的另一个名字。您可以尝试传入
Object[]
来查看 .Net 的默认编组是否可以处理它。Have you tried using System.Runtime.InteropServices.Marshal.GetNativeVariantForObject?
Also, now that I jogged my memory, a Variant Array (VT_ARRAY) is really a SAFEARRAY by another name. You could try passing in an
Object[]
to see if .Net's default marshalling will handle it.