The problem for API function "InsertPart2"

Hi,

I try insert the template part file into current part by using API function "InsertPart2".

It can work successfully in the very beginning.

However, it would lead the SoildWorks crash if call this function too often.

Is any limits to using this API function ?

I develop the Add-In by using C++ COM.

The code is as follows.

ISldWorks* pSldWorks;

IModelDoc2*  pSilentDoc,CurrentDoc;

IPartDoc* CurrentPart;

CComBSTR importFileName;

importFileName=L"C:\\\\TempPart1.sldprt";

long Errors,Warnings;

// Open the template doc in the backgroud

pSldWorks->OpenDoc6(importFileName,swDocPART, swOpenDocOptions_Silent, NULL, &Errors, &Warnings, &pSilentDoc);

// To get the current part handle

pSldWorks->get_IActiveDoc2(&CurrentDoc);

CurrentDoc->QueryInterface(IID_IPartDoc, (LPVOID *)&CurrentPart);

IFeature* pFea = NULL;

 

if (CurrentPart)

{

long option = swInsertPartImportSolids+swInsertPartBreakLink;

CurrentPart->InsertPart2(importFileName,     option,     &pFea);

if (pFea == NULL)

      return false;

}

It will lead the randomly crash when using the API function "InsertPart2".

Please help me to figure out where the problem is.

Thanks a lot

Joe

SolidworksApi macros