好的,所以我实际上是在使用 Axis Media Control SDK 来连接网络摄像机(http://www.axis.com/techsup/cam_servers/dev/activex.htm)。我通过包装器调用的 OCX 函数看起来像;
HRESULT GetCurrentImage(int theFormat, [C++]
VARIANT* theBuffer,
LONG* theBufferSize
);
包装器由 Axis 提供。使用 .NET Reflector 我已经反汇编了包装函数;
public: virtual void __gc* GetCurrentImage(Int32 __gc* theFormat, [Out] Object __gc* *theBuffer, [Out] Int32 __gc* *theBufferSize)
{
if (this->ocx == 0)
{
throw __gc new InvalidActiveXStateException(S"GetCurrentImage", ActiveXInvokeKind::MethodInvoke);
}
this->ocx->GetCurrentImage(theFormat, out theBuffer, out theBufferSize);
}
所以它没有做任何聪明的事情,只是传递了一大块内存。在 C++ CLI 语法中,模板看起来像;
GetCurrentImage(int theFormat, System::Object ^% theBuffer, int % theBufferSize)
所以我的问题变成了如何传递这块内存来写入,然后将其恢复回.NET 对象。我试过这个;
unsigned char c[100];
GetCurrentImage(0, (System::Object)c, BufSize);
但显然它不起作用。