Forum Discussion

arthurqv's avatar
arthurqv
Occasional Contributor
7 years ago
Solved

I am trying to add several source files to a profiling area in C++ in Visual Studio2015.

I tried to mimic the VB script example, but my program always crashes when I try to add a second item to my created area. If I only add one item, it works fine. Does anybody have a C++ VS2015 example for adding items to an area using Area Manager?

My code looks like this:

 for (long i = 0; i < modCount; i++)
            {
                long itemCount;
                BSTR FullName = 0;;
                hr = DebugInfoManager->get_Module(i, &modObject);
                hr = modObject->get_ItemCount(dtSourceFile, &itemCount);
                for (long j = 0; j < itemCount; j++)
                {
                    CComPtr <IaqCOMAccessDbgSymbol>  SrcFileSymbol;
                    hr = modObject->get_Item(dtSourceFile, j, &SrcFileSymbol);
                    SrcFileSymbol->get_FullName(&FullName);
                    if (isFileNameOfInterest(FullName, listFileNames))
                    {
                        hr = aqArea->AddItem(SrcFileSymbol, &areaValue); <== crashes the second time around
                    }
                }
            }

 

Thanks in advance

  • arthurqv's avatar
    arthurqv
    7 years ago

    Actually, I solved my problem, but I'm not 100% sure why:

    The key was to reset the two CComPtr inside the loop. Not sure why, but I am not a COM expert:

    CComPtr <IaqCOMAccessAreaItem> areaValue

    CComPtr <IaqCOMAccessDbgSymbol> SrcFileSymbol;

    ......

    for (long j = 0; j < itemCount; j++)

     

    {

           areaValue = 0;

           SrcFileSymbol = 0;

           hr = modObject->get_Item(dtSourceFile, j, &SrcFileSymbol);

           SrcFileSymbol->get_FullName(&FullName);

           if (isFileNameOfInterest(FullName, listFileNames))

     

           {

                  hr = aqArea->AddItem(SrcFileSymbol, &areaValue);

     

           }

    }

    Thanks to all for the suggestions.

4 Replies

  • arthurqv's avatar
    arthurqv
    Occasional Contributor

    The link to the VB script I am trying to mimic in VS2015 C++ is:

    https://support.smartbear.com/viewarticle/43119/#ID0ERKAE

     

    And it is NOT the app that crashes. It is the program that tries to add a second file to the profiling area in the AQTime project.

    I must be doing something dumb, but it's not obvious (to me) after staring at and debugging the code for a while.

     

    Thanks for any help

      • arthurqv's avatar
        arthurqv
        Occasional Contributor

        Actually, I solved my problem, but I'm not 100% sure why:

        The key was to reset the two CComPtr inside the loop. Not sure why, but I am not a COM expert:

        CComPtr <IaqCOMAccessAreaItem> areaValue

        CComPtr <IaqCOMAccessDbgSymbol> SrcFileSymbol;

        ......

        for (long j = 0; j < itemCount; j++)

         

        {

               areaValue = 0;

               SrcFileSymbol = 0;

               hr = modObject->get_Item(dtSourceFile, j, &SrcFileSymbol);

               SrcFileSymbol->get_FullName(&FullName);

               if (isFileNameOfInterest(FullName, listFileNames))

         

               {

                      hr = aqArea->AddItem(SrcFileSymbol, &areaValue);

         

               }

        }

        Thanks to all for the suggestions.