Why is my code slower using #import "progid:typelib" than using "MFC Class From TypeLib"?
- by Pakman
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!