IRunningObjectTable.Register始终将pdwRegister设置为65536,这是一个无效值 [英] IRunningObjectTable.Register always sets pdwRegister to 65536, an invalid value

查看:92
本文介绍了IRunningObjectTable.Register始终将pdwRegister设置为65536,这是一个无效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IRunningObjectTable.RegisterIRunningObjectTable.Revoke,如中所示本教程.我的VBScript客户端最初调用方法没问题,但是当C#COM服务器进行处理时,我总是收到值不在预期范围内"的异常.这是由于下面的注释行:

I'm using IRunningObjectTable.Register and IRunningObjectTable.Revoke as shown in this tutorial. My VBScript client initially calls methods no problem, but when the C# COM server disposes, I always receive a "Value does not fall within the expected range" exception. This is due to the commented line below:

private const int ACTIVEOBJECT_STRONG = 0x0;

[DllImport("ole32.dll")]
private static extern int CreateBindCtx(int reserved,
    out IBindCtx bindCtx);

[DllImport("oleaut32.dll")]
private static extern int RegisterActiveObject
    ([MarshalAs(UnmanagedType.IUnknown)] object punk,
    ref Guid rclsid, 
    uint dwFlags, 
    out int pdwRegister);

// register instance so it appears in ROT
private static int Register<T>(T classToRegister) 
{  
    int pdwRegister;
    Guid guid = Marshal.GenerateGuidForType(typeof(T));

    RegisterActiveObject(classToRegister, 
        ref guid, 
        ACTIVEOBJECT_STRONG, 
        out pdwRegister);

    return pdwRegister;
}

// do stuff in VBScript before disposal calls Revoke with the stored 
// pdwRegister value from the method above

// revoke instance so it's removed from ROT
private static void Revoke(int pdwRegister)
{
    IBindCtx bc;
    CreateBindCtx(0, out bc);

    IRunningObjectTable rot;
    bc.GetRunningObjectTable(out rot);
    // EXCEPTION: pdwRegister is *always* 65536, an invalid value!
    rot.Revoke(pdwRegister);      
}

如果我终止程序并忽略该异常,则该实例通常会将其自身从ROT中删除.但是,一段时间后,我注意到ROT中应用程序GUID的多个实例,并且我的VBScript客户端在GetObject(,"my.id")上开始失败.有什么想法吗?

If I terminate the program and ignore the exception, the instance usually removes itself from the ROT. However, after some time, I've noticed multiple instances of my app's GUID in the ROT and my VBScript client starts failing on GetObject(, "my.id"). Any thoughts?

推荐答案

我怀疑您没有正确维护对象的生存期.我已经做过同样的事情,但是使用了两个单独的类型,将每个类型都放在运行对象表"中.

I suspect that you are not maintaining the lifetime of the object correctly. I've done the same thing you have, but used two separate types, placing each of them in the Running Object Table.

像您一样,我放置在表中的第一个对象收到的句柄值为65536.但是,对于第二项,我收到的是不同的句柄.

Like you, the first object I placed in the table, I received a handle value of 65536. However, for the second item, I received a different handle.

但是,调用 RevokeActiveObject ,两个调用都返回S_OK的HRESULT.

However, when calling RevokeActiveObject, both calls returned an HRESULT of S_OK.

某事告诉我,在调用撤消对象之前,您的对象已被处置.

Something tells me that your object is being disposed of before the calls to revoke them are made.

要么,要么没有增加/减少ROT上项目的引用计数.

Either that, or something is not incrementing/decrementing the reference count of the item on the ROT.

这篇关于IRunningObjectTable.Register始终将pdwRegister设置为65536,这是一个无效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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