[great-users] export an image of a system structure

Kevin Smyth kevin.m.smyth at gmail.com
Wed Jul 15 09:03:17 CDT 2015


Hi Tim,

icon_value should've set to NULL after the call to SysFreeString
You should not call SysFreeString on the uninitialized icon_value (first iteration of loop)
icon_path should be created using SysAllocString

To avoid these sorts of error, I would suggest using _bstr_t or CComBstr instead of raw BSTRs. 

> On Jul 15, 2015, at 7:48 AM, Belschner, Tim <tim.belschner at ils.uni-stuttgart.de> wrote:
> 
> Hello everybody,
>  
> 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.
> 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:
>  
> ##################### CODE START ##########################
>  
> BSTR icon_path;                              // "icon"
> BSTR icon_value;                            // e.g. "module.gif"
> std::string str_name, str_icon_name;
> CComPtr<IUnknown> pUnk;
>                
> set<Udm_VS10::Object> objs = ModelMain.GetChildObjects();
>  
> for (set<Udm_VS10::Object>::const_iterator it = objs.begin(); it != objs.end(); it++)
> {
>                 icon_path = L"/icon";
>                 SysFreeString(icon_value);
>                
>                 pUnk.Attach(UdmGme::Udm2Gme( *it ));
>                 CComQIPtr<IMgaFCO> pFCO = pUnk;
>                 HRESULT hr = pFCO->get_RegistryValue( icon_path, &icon_value);
>                
>                 _com_error err(hr);
>                 LPCTSTR errMsg = err.ErrorMessage();
>                
>                 std::string str = BstrToStdString(icon_value);
>                 std::cout << green << "the icon name is " << str << "error message ::" << errMsg << white << endl;
>                
>                 pUnk.Release();
> };
>                
> ##################### CODE END ##########################
>  
> 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?
> And if there is a more simple way of exporting a selection of objects, please let me know too.
>  
> Thanks in advance and best regards
>  
> Tim
>  
> _______________________________________________
> great-users mailing list
> great-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/cgi-bin/mailman/listinfo/great-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.isis.vanderbilt.edu/pipermail/great-users/attachments/20150715/9ef5dd3a/attachment.html>


More information about the great-users mailing list