Author Topic: Error HRESULT E_FAIL has been returned from a call to a COM component  (Read 15352 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #15 on: July 28, 2010, 02:33:13 AM »
OldIdPtr returns an IntPtr, so try using ToIntXX  :-)     
I tried this methods use (ToInt32() for x86 and ToInt64() for x64) before it's topic created. But it not help me. (((

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #16 on: July 28, 2010, 03:19:27 AM »
I see it crashes pretty hard, how are your c++ skills?  :wink:

Andrey Bushman

  • Swamp Rat
  • Posts: 864
All Ok!
« Reply #17 on: July 28, 2010, 03:50:23 AM »
Thanks All!

My mistake: I forget use AddNewlyCreatedDBObject method of Transaction

It work:
Code: [Select]
Document dwg = acadApp.DocumentManager.MdiActiveDocument;
Database db = dwg.Database;
using (Transaction t = dwg.TransactionManager.StartTransaction())
{
    TableStyle ts = new TableStyle();
    ObjectId stId = ts.PostTableStyleToDatabase(db, "MyTableStyle");               
    t.AddNewlyCreatedDBObject(ts, true);
    AcadApplication app = (AcadApplication)acadApp.AcadApplication;
    int c = stId.OldIdPtr.ToInt32();//Good work!
    ////or
    //int c = (int)stId.OldIdPtr;// It to good work!
    object x = app.ActiveDocument.ObjectIdToObject(c);
    IAcadTableStyle2 ts2 = (IAcadTableStyle2)x;
    t.Commit();
}
And It work too:
Code: [Select]
Document dwg = acadApp.DocumentManager.MdiActiveDocument;
Database db = dwg.Database;
using (Transaction t = dwg.TransactionManager.StartTransaction())
{
    TableStyle ts = new TableStyle();
    DBDictionary tableStylesDict = (DBDictionary)t.GetObject(db.TableStyleDictionaryId, OpenMode.ForWrite);
    ObjectId stId = tableStylesDict.SetAt("MyTableStyle", ts);
    t.AddNewlyCreatedDBObject(ts, true);
    AcadApplication app = (AcadApplication)acadApp.AcadApplication;
    ////int c = stId.OldIdPtr.ToInt32();//Good work!
    ////or
    int c = (int)stId.OldIdPtr;// It to good work!
    object x = app.ActiveDocument.ObjectIdToObject(c);
    IAcadTableStyle2 ts2 = (IAcadTableStyle2)x;
    t.Commit();
}

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #18 on: July 28, 2010, 03:52:40 AM »
I see it crashes pretty hard, how are your c++ skills?  :wink:
I do not know C++. I know C# only.  :oops:

Glenn R

  • Guest
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #19 on: July 28, 2010, 04:51:13 AM »
You're missing my point. If you have an ObjectId, for a TableStyle in this instance, just open it up as normal and cast it to 'TableStyle'.

So, let's say your variable for the opened TableStyle is ts; call ts.AcadObject as IAcadTableStyle; as I showed in my example. There is no need to use special incantations on ints/longs or whatever that shoehorn an ObjectId.

Every RCW for an AutoCAD object provides this method, which get's a COM interface pointer to the underlying ARX/C++/C# object.

Glenn R

  • Guest
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #20 on: July 28, 2010, 04:52:08 AM »

Quote from: Glenn in the UK in the middle of Summer
IAcadTableStyle comTableStyle = ts.AcadObject as IAcadTableStyle;

I thought I was the only one to name COM variable prefixed with com....   :wink:

Not the only one, as it makes sense...great minds blah blah ;-)

Glenn R

  • Guest
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #21 on: July 28, 2010, 04:53:42 AM »
Ripper Rita, that helps

I added to Kerry's post a method to unmangle the names in the file dumpbin produces.

Thanks Paul. I found out last night, that you can get the 'undecorated' name in one of DependencyWalker's windows as well...just right-click on the entry once you've found it.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #22 on: July 28, 2010, 04:55:02 AM »
Good Job Hwd  8-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #23 on: July 28, 2010, 04:56:40 AM »
< .. >
Every RCW for an AutoCAD object provides this method, which get's a COM interface pointer to the underlying ARX/C++/C# object.

for those following :
RCW =>>  Runtime Callable Wrapper

http://msdn.microsoft.com/en-us/library/8bwh56xe.aspx
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: All Ok!
« Reply #24 on: July 28, 2010, 04:59:17 AM »
Thanks All!
I forget use AddNewlyCreatedDBObject method of Transaction


Excellent news that it's working for you :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #25 on: July 28, 2010, 05:09:13 AM »
You're missing my point. If you have an ObjectId, for a TableStyle in this instance, just open it up as normal and cast it to 'TableStyle'.

So, let's say your variable for the opened TableStyle is ts; call ts.AcadObject as IAcadTableStyle; as I showed in my example. There is no need to use special incantations on ints/longs or whatever that shoehorn an ObjectId.

Every RCW for an AutoCAD object provides this method, which get's a COM interface pointer to the underlying ARX/C++/C# object.

and

< .. >
Every RCW for an AutoCAD object provides this method, which get's a COM interface pointer to the underlying ARX/C++/C# object.

for those following :
RCW =>>  Runtime Callable Wrapper

http://msdn.microsoft.com/en-us/library/8bwh56xe.aspx

Thank you!

LE3

  • Guest
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #26 on: July 28, 2010, 12:18:40 PM »
Where's your mistake? Apart from still using COM when I showed you in your other thread how to use PInvoke...

Hi Glenn,
About the COM usage, is that just for this case in particular? or in other words for what the OP routine is doing?

BTW, I have some large amount of code lines, that I am taking out my COM calls, so far noticed a difference in the speed, when selecting an object get all the properties, and pass those to a form (ie. tree control)... I still need the use of com objects - was thinking to probably post some of my code, but it is very specific, don't know...

So any comment you might have about COM...

Thank you Sir!  :)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #27 on: July 28, 2010, 03:24:44 PM »
Luis, if speed is an issue, perhaps you could issue asynchronous calls and continue working on other stuff until the thread completes the callback.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

LE3

  • Guest
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #28 on: July 28, 2010, 03:52:34 PM »
Luis, if speed is an issue, perhaps you could issue asynchronous calls and continue working on other stuff until the thread completes the callback.
Hi Keith,

No, there is no issue about speed, just been trying to implement more or better all in .NET vs COM calls usage.. in example something like this below:

With COM
Code: [Select]
 
          SetXDictDat(ent, node);
            SetXDataDat(ent, node);
           
            if (ent is Autodesk.AutoCAD.Interop.Common.AcadBlockReference)//(ent.EntityName.CompareTo("AcDbBlockReference") == 0)
            {
                AcadBlockReference blk = ent as AcadBlockReference;
                if (blk != null && blk.HasAttributes)
                {
                    Object[] objAtt;
                    AcadAttributeReference Att;

                    childnode = new Node();
                    childnode.Text = "Attributes";
                   
                    nodtag = new NodeTag();
                    nodtag.strPropertyName = "Attributes";
                    nodtag.strPropertyDesc = "Block attributes";
                    nodtag.bIsCustom = true;
                    nodtag.bIsArray = true;
                    childnode.Tag = nodtag;
                   
                    node.Nodes.Add(childnode);
                    objAtt = (Object[])blk.GetAttributes();

                    for (i = 0; i < objAtt.Length; i++)
                    {
                        Att = objAtt[i] as AcadAttributeReference;
                        if (Att == null)
continue;

                        cnode = new Node();
childnode.Nodes.Add(cnode);
SetDatPropObj(objAtt[i], cnode);
//cnode.Text = "Attribute" + (i + 1).ToString();
cnode.Text = Att.TagString;

nodtag = new NodeTag();
nodtag.strPropertyName = "Attribute";
nodtag.strPropertyDesc = "Block attribute";
nodtag.bIsCustom = true;
nodtag.intIndex = i;
cnode.Tag = nodtag;

                    }
                }

            }
            node.Nodes.Sort();
            node.TreeControl.EndUpdate();
           
            return ("");

No COM (notice that here the need of a transaction on the com above, was very straight...)

Code: [Select]
            SetXDictDat(component, node);
            SetXDataDat(component, node);
            if (ent is BlockReference)
            {
                BlockReference blk = ent as BlockReference;
                Autodesk.AutoCAD.DatabaseServices.AttributeCollection attributes = blk.AttributeCollection;
                if (blk != null && attributes.Count != 0)
                {
                    childnode = new Node();
                    childnode.Text = "Attributes";

                    nodtag = new NodeTag();
                    nodtag.strPropertyName = "Attributes";
                    nodtag.strPropertyDesc = "Block attributes";
                    nodtag.bIsCustom = true;
                    nodtag.bIsArray = true;
                    childnode.Tag = nodtag;

                    node.Nodes.Add(childnode);
           
                    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
                    //Editor ed = doc.Editor;
                    //Database db = doc.Database;
                    using (Transaction tr = doc.TransactionManager.StartTransaction())
                    {
                        foreach (ObjectId objid in attributes)
                        {
                            DBObject obj = tr.GetObject(objid, OpenMode.ForRead, false) as DBObject;
                            if (obj != null)
                            {
                                AttributeReference att = obj as AttributeReference;

                                cnode = new Node();
                                childnode.Nodes.Add(cnode);

                                SetDatPropObj(obj, cnode);

                                //cnode.Text = "Attribute" + (i + 1).ToString();
                                cnode.Text = att.TextString;

                                nodtag = new NodeTag();
                                nodtag.strPropertyName = "Attribute";
                                nodtag.strPropertyDesc = "Block attribute";
                                nodtag.bIsCustom = true;
                                nodtag.intIndex = i++;
                                cnode.Tag = nodtag;
                            }
                        }

                        tr.Commit();
                    }
                }
            }
           
            node.Nodes.Sort();
            node.TreeControl.EndUpdate();

            return ("");

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Error HRESULT E_FAIL has been returned from a call to a COM component
« Reply #29 on: July 28, 2010, 03:58:17 PM »
Personally, as long as there isn't a performance issue, I don't see the problem with utilizing COM objects. Aside from the interops that must be shipped and/or installed on the end user's system, why not use the infrastructure available?

Of course once software developers move closer to fully managed code, the ability to utilize COM objects will be limited. One might wonder then, if there is a death knell for applications built with unmanaged code.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie