Jump to content
  • Advertisement
Sign in to follow this  
ednu

[C#] Obtain All Information from an Ocx

This topic is 3475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I am trying to use an ActiveX object in my c# application. The ActiveX object is installed in my pc and works properly in my c++ application. but when i tried to drag and drop the ocx from the toolbox to a winform in my c# application, an error poped up and said the ocx wasn't registered properly. so i tried to use reflection for dynamically innovating it't members and properties. firstly, i created a class inherited from AxHost. The type of ocx has been created as follow: ocxType = Type.GetTypeFromCLSID(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx")); // guid of the ocx object registered in my pc then in order to use the methods of this ocx, i used Type.Invokemember to do the job. ocxType.InvokeMember("MethodName", BindingFlags.InvokeMethod, null, this.GetOcx(), null); // "MethodName" is coming from the description documtation of the ocx object I tested the program and it executed successfully. However, when i tried to invoke the properties, unknown name exception was thrown all the time. but what confused me the most is that invoking the event in this way seemed not working at all. so here are my questions: what is the proper way to use the Ocx object in C# application? Are there any disadvantages of invoking members of ocx in this way? How can I bind all the information including event? Thank you soo much for all the help, ednu [Edited by - ednu on January 13, 2009 7:49:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
First thing I would try is unregistering and re-registering the OCX. You can do this from the command line as follows:

  • Click Start, select Run

  • Type cmd.exe and click OK

  • Type regsvr32 -u c:\path\to\file.ocx - this should tell you that the unregistration was successful

  • Type regsvr32 c:\path\to\file.ocx - this one should now say the registration was successful


Then see if that affects anything.

Share this post


Link to post
Share on other sites
Hi ApochPiQ,
Thanks for ur reply.

i've tried to uninstalled/installed it couple of times. but the exception remained.
thats why i gave up and tried to import ocx to my program via type invoking.

cheers,
ednu

Share this post


Link to post
Share on other sites
Can you post the exact error message you are receiving? What is the specific OCX file you're trying to use and where did you get it?

You shouldn't need to be calling anything directly via Invoke; the .Net framework has a very powerful COM interop layer, so using the object should behave just like a built in C# class/control.

Share this post


Link to post
Share on other sites
Have you tried using the automatic generation of an interop dll instead of writing the host yourself?
Visual studio can do that for you.

Just add a COM reference to the ocx to your project and the interop dll should be generated automagically.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!