Why is my code slower using #import "progid:typelib" than using "MFC Class From TypeLib"?

Posted by Pakman on Stack Overflow See other posts from Stack Overflow or by Pakman
Published on 2009-09-22T14:37:13Z Indexed on 2010/05/28 4:01 UTC
Read the original article Hit count: 268

Filed under:
|
|
|
|

I am writing an automation client in Visual C++ with MFC. If I right-click on my solution » Add » Class, I have the option to select MFC Class From TypeLib. Selecting this option generates source/header files for all interfaces. This allows me to write code such as:

#include "CApplication.h"
#include "CDocument.h"

// ... connect to automation server ...
CApplication *myApp = new CApplication(pDisp);
CDocument myDoc = myApp->get_ActiveDocument();

Using this method, my benchmarking function that makes about 12000 automation calls takes 1 second.

Meanwhile, the following code:

#import "progid:Library.Application"

Library::IApplicationPtr myApp;
// ... connect to automation server ...
Library::IDocumentPtr myDoc = myApp->GetActiveDocument();

takes about 2.4 seconds for the same benchmark. I assume the smart-pointer implementation is slowing me down, but I don't know why. Even worse, I'm not sure how to use #import construct to achieve the speeds that the first method yields. Is this possible? How or why not?

Thanks for your time!

© Stack Overflow or respective owner

Related posts about mfc

Related posts about automation