我的应用程序是一个.exe,自行注册腐烂。
[ComVisible(true)]
[ProgId("My.App")]
public class MyApp
{
public Interop_MyApp.IXXX XXX
{
get { return XXXImpl.Instance; } // -> Instance is derived from Interop_MyApp.IXXX, and static
}
public MyApp() { }
};
我开始的.exe以上,它的运行。
然后,我开始了其他的.exe,它试图获得XXX。
object o = Marshal.GetActiveObject("My.App"); // -> returns a __ComObject, fine
if (o == null)
throw new InvalidOperationException("Could not connect to My.App");
Type t = o.GetType();
object r = t.InvokeMember("XXX", BindingFlags.GetProperty | BindingFlags.Public, null, o, null); //--> returns a __ComObject, fine
Interop_MyApp.IXXX xxx = r as Interop_MyApp.IXXX; //----> here xxx is null?!
如果我叫t.GetProperties(),返回0? 哪里是“XXX”? 调用t.InvokeMember( “XXX” ......)成功!
任何帮助表示赞赏,感谢。