vb.net - Cannot create ActiveX component.Error while using GetObject in autocad 2011 -


i using below code use autocad object.

dim acadapp acadapplication  acadapp = getobject(, "autocad.application") 

'''and using below code create object -------------

acadapp = createobject("autocad.application") 

getting error "cannot create activex component". tried using 18,19 , various combination below :

acadapp = getobject(, "autocad.application.18") 

but nothing work. please help.

@locke : reply.i tried soltion below :

dim acadtype type  try    acadapp =       system.runtime.interopservices.marshal.getactiveobject("autocad.application.18.1")    ''above code din't worked tried below code     ' acadapp = directcast(marshal.getactiveobject("autocad.application.18.1"),      'acadapplication)  catch ex exception              acadtype = type.gettypefromprogid("autocad.application")   acadapp = directcast(activator.createinstance(acadtype, true), acadapplication)            end try 

showing exception :

unable cast com object of type 'system.__comobject' interface type 'autocad.acadapplication'. operation failed because queryinterface call on com component interface iid '{8e75d910-3d21-11d2-85c4-080009a0c626}' failed due following error: no such interface supported (exception hresult: 0x80004002 (e_nointerface)).

here's typically use when dealing autocad interop. checks running instance, , creates new 1 if necessary:

private static acadapplication getacadapp(string progid) {     // create return application     acadapplication returnapp = null;      try     {         // try getting running instance         returnapp = (acadapplication)marshal.getactiveobject(progid);     }     catch (comexception)     {         try         {             // try creating new instance             type acadtype = type.gettypefromprogid(progid);             returnapp = (acadapplication)activator.createinstance(acadtype, true);         }         catch (comexception)         {             // report failure             messagebox.show(string.format("cannot create object of type \"{0}\"", progid));         }     }      // return application     return returnapp; } 

an acadapplication com object can set this:

// get/create autocad instance var acadapp = getacadapp("autocad.application.18"); 

regardless of c# or vb.net, using marshal.getactiveobject , activator.createinstance better ways approach this.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -