0

Trying to use some COM-objects in my C# app.

1-st variant:

using AXVLC;

Type t = Type.
           GetTypeFromCLSID(
           Guid.Parse("E23FE9C6-778E-49D4-B537-38FCDE4887D8")
           );

AXVLC.VLCPluginClass vid = Activator.CreateInstance(t) as VLCPluginClass;

But getting such error: Interop type 'AXVLC.VLCPluginClass' cannot be embedded. Use the applicable interface instead. ComObjectCalls

I have understood that the COM object does not expose a public constructor then I shall have to find some other means of using the object. A lot of time COM objects use the factory model to create instances of objects (eg. IClass instance = COMClass.CreateInstance(); )

Or trying using Activator.CreateInstance()

Also I have another question with COM objects: - I have using dynamic type: dynamic shell = AutomationFactory.CreateObject("WMPlayer.OCX.7");

It creates - ok. But how to get known, which metods I can use in it. How can I cast it?

The main problem is: that I want to access COM-object with Silverlight application. So there is a way to work with dynamic/expondo object or calling with P/Invoke some native libraries in Silverlight like:

[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "MessageBox")]
public static extern IntPtr MineMessageBox(int hWnd, string text,
string caption, uint type);

...
MineMessageBox(0, "Hello World", "Platform Invoke Sample", 0);

What is the best way to access COM-object features in Silverlight and also may to get all info in Runtime about this COM-object ( get methods, which I can call etc )

Thank you!

2 Answers 2

1

All COM objects conform to an interface, this is where your methods would come from.

In the case of the VLC ActiveX control, it's likely that you would instead of using AXVLC.VLCPluginClass, use AXVLC.VLCPlugin. This is akin to Office's interop of using Application instead of ApplicationClass.

In your second instance when using dynamic, a hacky way to get your IntelliSense working is to simply cast the return from CreateObject to the interface. You'll need to remember to remove it before you build, though, otherwise the cast will fail at runtime.

The alternative (and better way) would be to simply work off of the documentation for that COM object.

Sign up to request clarification or add additional context in comments.

Comments

1

Use AutomationFactory class and dynamic keyword (.net 4.0 / sl 4.0 minimum ).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.