如何将结构指针从COM服务器传递到.net客户端? [英] How can I pass structure pointer from COM server to .net client?

查看:71
本文介绍了如何将结构指针从COM服务器传递到.net客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是COM&的初学者. .net互操作性.
我正在通过RCW(运行时可调用包装程序)将.net客户端中使用的COM服务器dll.
我已经在COM服务器应用程序中定义了一个自定义结构,该结构要传递给.net客户端.
如何公开此结构,是否有任何方法可以将其指针传递给客户端?
我尝试使用VARIANT *,但这给了我以下异常:
"COMClient.exe中发生了类型为"System.NullReferenceException"的未处理的异常"
附加信息:对象引用未设置为对象的实例."


与STA和MTA有关吗?

请帮助我...

在此先感谢.

Hi All,

I am a beginner in COM & .net interoperability.
I am having COM server dll which I am using into .net client through RCW(Runtime Callable Wrapper).
I have defined one custom structure in COM server application which I want to pass to .net client.
How can I expose this structure and is there any means to pass its pointer to client?
I tried using VARIANT* but this gives me exception as follows:
"An unhandled exception of type ''System.NullReferenceException'' occurred in COMClient.exe
Additional information: Object reference not set to an instance of an object."


Is it a problem related to STA and MTA?

Please help me in this...

Thanks in Advance.

推荐答案

您无法在com和.net之间传递ptr-在另一个存储器中不能寻址一个存储器

您需要做的是发送数据的副本,然后将其编组到.net

看看com上的size_is idl服装

C#ATLCOM互操作代码摘录-第1部分 [
you can''t pass ptr''s between com and .net - one''s memory is not addressable in the other

What you''ll have to do is send a copy of the data over, and then marshal into .net

have a look at the size_is idl attibute on the com side

There''s a good article here C# ATLCOM Interop code snipperts - Part 1[^]


这篇关于如何将结构指针从COM服务器传递到.net客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆