gpt4 book ai didi

c# - 将项目添加到 ROT(运行对象表)

转载 作者:行者123 更新时间:2023-11-30 16:56:50 27 4
gpt4 key购买 nike

我知道如何使用 *****.GetActiveObject(ProgId),但问题是我使用此代码行的几个应用程序没有添加到 ROT,即使它们已经打开,我得到HRESULT 错误。但是,如果我单击另一个应用程序然后返回到原始应用程序,代码行就可以正常工作。

我之所以如此含糊其辞,是因为这是我在 10 多个应用程序中遇到的问题。

我不发布代码的原因是因为我不认为这个问题是基于代码的,而是我认为这个问题是由于我缺乏理解造成的。

我遇到此问题的最重要程序之一是“Microsoft Excel”。我想要做的就是能够在特定单元格启动用户。

我已经遍地查看了如何在 Excel 中使用 *****.GetActiveObject(ProgId) 的合理解释,但是,似乎没有任何合理的答案。该程序可能是用 c# 编写的,但是,如果它在 visual basic 中更简单,那不是问题

最佳答案

http://support.microsoft.com/kb/316126

COM servers are expected to register themselves in Running Object Table after startup. Office programs register themselves when they lose focus. If a program tries to attach to a running instance before the program loses focus, you may receive an error message. For additional information about how to work around this problem, click the article number below to view the article in the Microsoft Knowledge Base: 316125 PRB: Visual C# .NET Error Attaching to Running Instance of Office Application

Using code, you can change focus from the Office application to your own application (or to some other application) to allow it to register itself in the ROT. Additionally, if your code is starting the executable (.exe) file for the Office application, you may need to wait for the Office application to finish loading before you attempt to attach to the running instance.

确保在尝试连接之前激活另一个窗口。如示例所示,您可以使用 Form.Activate聚焦您自己的表单,从而导致 Office 应用失去焦点。

关于c# - 将项目添加到 ROT(运行对象表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27444419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com