0

我有一个客户端服务器应用程序执行以下操作:
服务器启动并监听特定端口。许多 corelDraw 会话手动或以编程方式启动。每个 corel 会话(客户端)连接到发送当前进程 ID 的服务器。服务器将所有连接保存在 listView 中,并且 EndPoint 可以根据每个连接更改(发送和接收)消息。现在我想使用特定此类进程 ID 的 COM 对象。我试过了:

using corel = Corel.Interop.VGCore;

int processID = Convert.ToInt32(lstClients.SelectedItems[0].SubItems[4].Text);//process ID string
Process corProc = Process.GetProcessById(processID);
int hwnd = (int)Process.GetProcessById(corProc).MainWindowHandle
this.Activate();
bool IsCom = corProc.GetType().IsCOMObject; // return false...
corApp = (corel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Corel.Application") // returns just the last session (not according to existing process ID
//tried also:
corApp = (corel.Application)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(corProc.Handle); // error...
//tried:
corApp = (corel.Application)Convert.ChangeType(corProc, typeof(corel.Application)); // error: 'Object must implement IConvertible.'

有没有办法获得 corel COM 对象,让我有机会像这样使用 Corel.Application 对象?

MessageBox.Show(corApp.Documents.Count.ToString());

提前致谢!

4

1 回答 1

0

没有从 PID 获取对象的通用机制,但根据 OLE 服务器的实现,您可以使用AccessibleObjectFromWindow. 有关针对 PowerPoint 的类似示例,请参阅以编程方式启动 Office 应用程序。

您也可以尝试使用 RotView来查看应用程序是否已在运行对象表中注册。例如,Visual Studio 注册一个名字对象,!VisualStudio.DTE.14.0:21604其中 14.0 是版本,21604 是进程 ID。

ROTView 显示带有进程 ID 的 VisualStudio 条目

于 2017-01-26T19:52:56.437 回答