<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Hi Tim,</div><div><br></div><div>icon_value should've set to NULL after the call to SysFreeString</div><div>You should not call SysFreeString on the uninitialized icon_value (first iteration of loop)</div><div>icon_path should be created using SysAllocString</div><div><br></div><div>To avoid these sorts of error, I would suggest using _bstr_t or CComBstr instead of raw BSTRs. </div><div><br>On Jul 15, 2015, at 7:48 AM, Belschner, Tim <<a href="mailto:tim.belschner@ils.uni-stuttgart.de">tim.belschner@ils.uni-stuttgart.de</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--><div class="WordSection1"><p class="MsoNormal"><span lang="EN-US">Hello everybody,<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-US">we would like to export an image of a system structure based on our metamodel, similar to the GME “Print to Metafile” function. Since we weren’t able to use the underlying functions of “Print to Metafile” in a transformation, we would like to draw all icons on a canvas and save it to a file. For this, we need to access the icon names of each object.<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">The issue is, that in our code the icon name is returned correctly for the first element, e.g. “module.gif” but not for the following ones. Beginning from the second object resp. loop, an error is returned and the value of “icon_value” is always “Aspect”. Following the code:<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-US">##################### CODE START ##########################<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-US">BSTR icon_path;                              // "icon"<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">BSTR icon_value;                            // e.g. "module.gif"<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">std::string str_name, str_icon_name;<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">CComPtr<IUnknown> pUnk;<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">set<Udm_VS10::Object> objs = ModelMain.GetChildObjects();<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-US">for (set<Udm_VS10::Object>::const_iterator it = objs.begin(); it != objs.end(); it++) <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                icon_path = L"/icon";<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                SysFreeString(icon_value);<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                pUnk.Attach(UdmGme::Udm2Gme( *it ));<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                CComQIPtr<IMgaFCO> pFCO = pUnk;<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                HRESULT hr = pFCO->get_RegistryValue( icon_path, &icon_value);<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                </span>_com_error err(hr);<o:p></o:p></p><p class="MsoNormal">                LPCTSTR errMsg = err.ErrorMessage();<o:p></o:p></p><p class="MsoNormal">                <o:p></o:p></p><p class="MsoNormal">                <span lang="EN-US">std::string str = BstrToStdString(icon_value);<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                std::cout << green << "the icon name is " << str << "error message ::" << errMsg << white << endl;<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                 <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                pUnk.Release();<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">};<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">                <o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">##################### CODE END ##########################<o:p></o:p></span></p><p class="MsoNormal"><o:p> </o:p></p><p class="MsoNormal"><span lang="EN-US">Could someone please give us a hint or provide a code snippet about how to access the name of the icon resp. use “CComPtr<IUnknown> pUnk” in a correct way?<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US">And if there is a more simple way of exporting a selection of objects, please let me know too.<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-US">Thanks in advance and best regards<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p><p class="MsoNormal"><span lang="EN-US">Tim<o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>great-users mailing list</span><br><span><a href="mailto:great-users@list.isis.vanderbilt.edu">great-users@list.isis.vanderbilt.edu</a></span><br><span><a href="http://list.isis.vanderbilt.edu/cgi-bin/mailman/listinfo/great-users">http://list.isis.vanderbilt.edu/cgi-bin/mailman/listinfo/great-users</a></span><br></div></blockquote></body></html>