Solved

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

Posted on 2004-04-30
5
496 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

749 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