我有一个客户端服务器应用程序执行以下操作:
服务器启动并监听特定端口。许多 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());
提前致谢!