COM RCW 上的地址引用
是否可以增加未知接口上的 RCW 引用计数? (即不是底层 COM 对象的引用计数)
我有一些旧的 COM 服务器代码
int Method1(object comobject) {
try {
// do something with comobject
return 0;
}
finally {
Marshal.ReleaseComObject(comobject);
}
}
此代码工作正常,但现在我需要从另一个方法调用它。
int Method2(object comobject) {
int result = Method1(comobject);
// Do something with combject
}
comobject 的类型会有所不同(这就是它是 object 的原因)
Is it possible to increase the RCW reference count on an unknown interface?
(i.e. not the reference count on the underlying COM object)
I have some old COM server code
int Method1(object comobject) {
try {
// do something with comobject
return 0;
}
finally {
Marshal.ReleaseComObject(comobject);
}
}
This code works fine but now I need to call it from another method.
int Method2(object comobject) {
int result = Method1(comobject);
// Do something with combject
}
The type of comobject will vary (that is why it is object)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种方法,RCW 计数计算对象已被封送的次数,您可以通过执行额外的封送来增加此数字。
我不确定是否会推荐使用此方法,最好尝试摆脱
ReleaseComObject
调用。如需进一步阅读,请参阅我撰写的关于该主题的博客文章。
There is a way, the RCW count counts how many times the object has been marshaled you can increase this number by performing an additional marshal.
I'm not sure I would recommend using this method, it's probably better to try and get rid of your
ReleaseComObject
calls.For further reading, see this blog post on the subject I wrote.
有 Marshal.AddRef() 方法,但引用计数更改错误。我很确定直接增加 RCW 计数是不可能的。把自己从深渊中挖出来,修复旧代码。
There's the Marshal.AddRef() method, wrong reference count change though. I'm pretty sure incrementing the RCW count directly is not possible. Dig yourself out of the deep hole you're in and fix the old code.