Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get a pointer to an object from a IDispatch pointer ?

Posted on 2004-04-30
5
Medium Priority
?
508 Views
Last Modified: 2013-11-18
Hope i post in the correct topic: I'm programming in C++ with COM to control Autocad.
--------------------------------------------
For those not familar with Autocad programming, here is what is, i believe, a COM problem : at some part of my code, I have to transform a IAcadObjectPtr (derived from IDispatch) to a IAcadAttributeReferencePtr (derived from IAcadObject). This line does the job :
pAcadAttribRef = pAcadObject;
I have to execute this line very often in my program, and it's very slow : 1500 executions of that line take about 30 seconds on a P4 2.8 (with debug code, but release is not much faster) !
When i enter into that line, i see that's just a call to QueryInterface(). Is there a way to accelerate it ?

--------------------------------------------
For those familar with Autocad programming, here is the all story :
Given a BlockReference, i need to get one of its AttributeReference from the Attribute tag (its name). I wrote this function :

IAcadAttributeReferencePtr DrvAcad::FindAttributeRefByTag(IAcadBlockReferencePtr pAcadBlockRef, const CString& strTag)
{
_variant_t arrayAttrib; // array of AttributeRef objects
long lbound, ubound;
IAcadAttributeReferencePtr AttribRef = NULL;
IAcadObjectPtr pObject;
arrayAttrib = pAcadBlockRef->GetAttributes();
SafeArrayGetLBound(arrayAttrib.parray, 1, &lbound);
SafeArrayGetUBound(arrayAttrib.parray, 1, &ubound);
for (long i = lbound; i <= ubound; i++)
{
SafeArrayGetElement(arrayAttrib.parray, &i, &pObject);
AttribRef = pObject; // very slow !
if (AttribRef->GetTagString() == strTag)
break;
}
return AttribRef;
}

GetAttributes() returns an array, but the array elements are not directly AttributeReferences; they are AcadObjects that i have to transform in AttributeReferences to finally be able to call AttribRef->GetTagString(). Anyway that's what i have been told, and i didn't find another way to get an attributeRef.

In some part of my program, i process about 300 block references and i have to call this function 5 times for each blockref (i need to set the values for 5 attributes). On a P4 2.8Ghz it takes almost 1 minute (with debug code, but release is not much faster). Much too slow because clients may have thousands of blocks to process !
By commenting some parts of the code and timing, i get to the conclusion that one of the main source of 'slowness' is the line AttribRef = pObject : it's responsible for about 30 secondes. When i enter into that line, i see that's just a QueryInterface().
I have to say i don't really understand the fine lines of COM programming (that would take me weeks of learning ...), i just try to pilot Autocad.
If someone has an explanation, or better a faster way for getting an AttributeRef ...
0
Comment
Question by:JP_Goblet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 10958681
Nope - you have to QueryInterface.

Best option for speeding up is to cache the result, if you're going to do the conversion on the same pointer lots of times.

Cross-process COM is actually pretty slow. (As we now know, to our cost!)

0
 

Author Comment

by:JP_Goblet
ID: 10959183
I'm not sure that caching that sort of  pointer is a good idea : this pointer is created and managed by Autocad itself, i have no garantee it will stay the same during the lifespan of my application.

Anyway my problem is now resolved ... by rebooting : after reboot the debug code is still relatively slow (times have been halved) but release code is now fast enough : just a few seconds.  I can think of a possible explication for this salvating reboot : in debug mode i frequently stop my application brutally (stop debugging in the visual studio) --> probably all the stuff associated with COM was not cleanly removed; after several of these stops, the COM processing was frozen in all that garbage ? ...

I consider the question is closed.

JPG
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10989765
Closed, 250 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question