C++ CLI 神秘函数调用
所以我试图调用一个函数,它是 OCX 对象的托管包装器。 有很大的困难。 功能是;
foo(System::Object ^% theBuffer)
其中“theBuffer”是字节数组。 'foo' 包装的非托管 OCX 的模板是
goo(VARIANT* theBuffer);
所以我尝试过;
System::Int32 buf[10];
foo(buf);
这失败了。 它
Bitmap ^b;
foo(b);
可以编译,但显然被调用的函数不会为我创建 .NET 位图。
所以我想问题是如何向这个函数传递一个它可以写入的内存块,然后在 .NET 世界中访问它。
谢谢
So I'm trying to call a function that is a manged wrapper around an OCX object. Having great difficulty. Function is;
foo(System::Object ^% theBuffer)
where 'theBuffer' is an array of bytes. The template for the unmanaged OCX which 'foo' wraps is
goo(VARIANT* theBuffer);
So I've tried;
System::Int32 buf[10];
foo(buf);
which fails. And
Bitmap ^b;
foo(b);
which compiles but obviously the called function is not going to create a .NET bitmap for me.
So I guess the question is how do I pass this function a block of memory it can write to and then get access to it back in .NET world.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法将
VARIANT
直接转换为缓冲区。首先,您需要通过检查
theBuffer->vt
来检查其中存储的对象类型。 返回值的类型为VARTYPE
。You can't convert a
VARIANT
to the buffer directly.First you need to check what kind of object is stored in it by checking
theBuffer->vt
. The returned value will be of the typeVARTYPE
.像这样的东西呢..
What about something like..
好的,我实际上正在使用 Axis Media Control SDK 与网络摄像机连接( http://www.axis.com/techsup/cam_servers/dev/activex.htm)。 我通过包装器调用的 OCX 函数如下所示:
包装器由 Axis 提供。 使用.NET Reflector我已经反汇编了包装函数;
所以它没有做任何聪明的事情,只是传递了一块内存。 在 C++ CLI 语法中,模板如下所示:
所以我的问题是如何传递这块内存来写入,然后将其恢复回 .NET 对象。 我尝试过这个;
但显然它不起作用。
ok so I'm actually using the Axis Media Control SDK to interface with a network camera ( http://www.axis.com/techsup/cam_servers/dev/activex.htm ). The OCX function I am calling via the wrapper looks like;
the wrapper is supplied by Axis. Using .NET Reflector I have disasembled the wrapper function;
So it's not doing anything smart, just passing a chunk of memory. In C++ CLI syntax the template looks like;
So my question becomes how do I pass this a chunk of memory to write to and then recover it back into a .NET object. I tried this;
but obviously it dosn't work.