COM returns type that does not implement any interface

孤街浪徒 提交于 2019-12-05 17:55:58

You have to use a Runtime Callable Wrapper

The method you need is this one

Try this :

    Type oType = Type.GetTypeFromProgID("InDesign.Application.CS3");
    if (oType != null)
    {
        object instance = Activator.CreateInstance(oType);// or any other way you can get it
        Application app = 
            (Application)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(instance, typeof(ApplicationClass));
    }

I didn't work with COM recently but as far I remember (and understood your problem) you can not cast ComObject like this:

   Application app = (Application)comObject;

but you should use as operator:

    Application = comObject as Application;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!