Layers._NewEnum (с++)

I can't loop through all the layers. How in CorelDraw (c ++) can you access the elements of a collection in a loop? For Shapes, I was able to loop through the range through the shaperange.item property. But for layers, the item[] property takes no arguments, and getitem[1] does not return a layer object. Everywhere in the collections (shapes, layers, pages) there is a _NewEnum property, but nowhere in the documentation is there a single example of how to use it in a loop (for i = 1, i<count, ++i) or in a loop (for each). This is probably some kind of mystery, since the documentation simply contains the function headers, but how they are implemented - you need to guess.

  • The solution was found independently. Since C++ is a strongly typed language, you must specify the exact type of the argument.

    If we look at any header of a function that refers to a collection of some objects, then we see that the argument must be of type _variant_t.

    __declspec(property(get=GetItem)) IVGShapePtr Item[];
    IVGShapePtr GetItem(const _variant_t& IndexOrName);

    And not just _variant_t, the index must be of type long.
    Therefore, accessing any element of any collection can look like this:

    VGCore::IVGShapePtr shape = doc->Shapes->GetItem(_variant_t(1L));

    Here "doc" is the previously retrieved VGCore::IVGDocumentPtr

    The loop might look like this:

    VGCore::IVGLayersPtr lrs = doc->ActivePage->Layers;
    VGCore::IVGLayerPtr lr = nullptr;

    for (long i = 1; i <= lrs->Count; i++)
        lr = lrs->Item[_variant_t(i)];
        if (lr->Shapes->Count == 0 && lr->IsSpecialLayer == VARIANT_FALSE) lr->Delete();

    in this example, I'm deleting all empty layers, and the layer doesn't have to be "master".