Visual Components' Community

New Thinking for Factory Simulation
Welcome to Visual Components' Community Sign in | Help
in Search

How to select a component with COM API (C++)

Last post ti, huhti 28 2009 20:46 by mtw. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • ma, huhti 27 2009 14:13

    • mtw
    • Top 25 Contributor
    • Joined on pe, helmi 22 2008
    • Posts 2

    How to select a component with COM API (C++)

    Hi there,

    I'm trying to add a component to the selection of 3DCreate but run into a COM-Exception: 

    Getting the component and selection pointers is no problem : 

    vcCOM::IvcComponentPtr cmp = m_appPtr->findComponent("TestComponent");

    vcCOM::IvcSelectionPtr sel = m_appPtr->getSelection(VC_SELECTION_COMPONENT);

    but how should i use the sel->addItem( ) method  which needs a IvcPropertyList ** as parameter ? 

    The following code querys successful the IvcPropertyList interface  but the addItem call fails :

    vcCOM::IvcPropertyList *pp = NULL;
    HRESULT h = cmp->QueryInterface(__uuidof(vcCOM::IvcPropertyList), (void **)&pp);
    sel->addItem(&pp);


    So it would be great if you could provide a short example on how to do the selection correctly...

    Thanks in advance,

    Michael 

     

     

  • ti, huhti 28 2009 16:32 In reply to

    • stabi
    • Top 10 Contributor
    • Joined on pe, helmi 22 2008
    • Helsinki, Finland
    • Posts 30

    Re: How to select a component with COM API (C++)

    Could you provide the following additional information?

    • Type of project you are developing (application, ActiveX DLL, ...)
    • Development environment
    • 3DCreate version

    The following code works in a native C++ application project in Visual Studio 2008, using 3DCreate 2009 SP2:

    vcCOM::IvcComponentPtr selectedComponent = m_vcApp->findComponent(componentName);
    vcCOM::IvcSelectionPtr componentSelection = m_vcApp->findSelection(L"Component");
    
    vcCOM::IvcPropertyListPtr propertyList = selectedComponent;
    vcCOM::IvcPropertyList* rawPropertyListPtr = propertyList;
    componentSelection->addItem(&rawPropertyListPtr);
    

    This code calls QueryInterface() in the IvcPropertyListPtr constructor. The IvcPropertyListPtr object also calls Release() on the property list pointer when it goes out of scope, something you would have had to do manually otherwise.

    Regards,

    - Staffan Bruun

    Filed under: , ,
  • ti, huhti 28 2009 20:46 In reply to

    • mtw
    • Top 25 Contributor
    • Joined on pe, helmi 22 2008
    • Posts 2

    Re: How to select a component with COM API (C++)

     Allright, that worked :-) Thanks a lot for your prompt help ! 

    I've got the same development environment and the problem was to use the appPtr->getSelection( [int] )   - since the VC_SELECTION_COMPONENT constant has not been generated by VC and I supposed it's 0 which it's probably not...

    As soon as I replace the getSelection call with your proposed findSelection call it works perfectly :-) 

    Thanks again,

    Michael 

     

     

     

     

Page 1 of 1 (3 items)