0

我目前正在开发一个小程序,我的编程技能不是最好的,但它已经很好用了,除了这部分。

我设法使用附加代码从我的可执行文件启动另一个程序。因此,如果我第一次循环通过以下代码片段,INCA程序将启动,并且我能够使用该程序的 API 函数。

但是......当INCA同时关闭并且我再次运行此代码时,没有任何反应并且我无法访问API,即使我之后手动启动INCA 。

    public bool Init()
    {
        var type = Type.GetTypeFromProgID( "Inca.Inca" );

        if ( type == null )
            return false;

        _inca = Activator.CreateInstance( type );

       return _inca != null;
    }

我错过了什么??我需要重新分配或释放 com 对象吗?

4

1 回答 1

0

在创建新实例之前关闭 api(有关详细信息,请参阅问题的评论)。

public bool Init()
{
    if ( _inca != null )
        _inca.Close();
    var type = Type.GetTypeFromProgID( "Inca.Inca" );

    if ( type == null )
        return false;

    _inca = Activator.CreateInstance( type );

    return _inca != null;
 }
于 2015-10-30T23:34:07.923 回答