I have the same code in C++ and C# for ArcMap. This code loads a document from disk and trying to get a picture for PictureSimbol object. But in case of C++ error occurs(HRESULT = E_UNEXPECTED 0x8000ffff). C# code works without any problem. Why such a difference may occur? (mxd_file_name the same in both cases)
C++ code
esriCarto::IMapDocumentPtr map_doc(esriCarto::CLSID_MapDocument);
map_doc->Open(mxd_file_name, L"");
esriCarto::IMapPtr mp = map_doc->Map[0];
esriCarto::IFeatureLayerPtr layer = mp->Layer[0];
esriCarto::ILegendInfoPtr inf = layer;
esriCarto::ILegendGroupPtr gr = inf->GetLegendGroup(0);
esriCarto::ILegendClassPtr cl = gr->Class[0];
esriDisplay::ISymbolPtr s = cl->Symbol;
esriDisplay::IMultiLayerFillSymbolPtr mls = s;
esriDisplay::IFillSymbolPtr fs = mls->Layer[0];
esriDisplay::IPictureFillSymbolPtr pfs = fs;
IPictureDisp * pic = 0;
HRESULT hr = pfs->get_Picture(&pic); // hr = E_UNEXPECTED 0x8000ffff catastrophic failure
map_doc->Close();
C#
ESRI.ArcGIS.Carto.IMapDocument map_doc = new ESRI.ArcGIS.Carto.MapDocument();
map_doc.Open(mxd_file_name);
ESRI.ArcGIS.Carto.IMap mp = map_doc.Map[0];
ESRI.ArcGIS.Carto.IFeatureLayer layer = mp.Layer[0] as ESRI.ArcGIS.Carto.IFeatureLayer;
ESRI.ArcGIS.Carto.ILegendInfo inf = layer as ESRI.ArcGIS.Carto.ILegendInfo;
ESRI.ArcGIS.Carto.ILegendGroup gr = inf.LegendGroup[0];
ESRI.ArcGIS.Carto.ILegendClass cl = gr.Class[0];
ESRI.ArcGIS.Display.ISymbol s = cl.Symbol;
ESRI.ArcGIS.Display.IMultiLayerFillSymbol mls = s as ESRI.ArcGIS.Display.IMultiLayerFillSymbol;
ESRI.ArcGIS.Display.IFillSymbol fs = mls.Layer[0];
ESRI.ArcGIS.Display.IPictureFillSymbol pfs = fs as ESRI.ArcGIS.Display.IPictureFillSymbol;
stdole.IPictureDisp pic = pfs.Picture; // works fine
map_doc.Close();
Update: There is no problem with IPictureDisp * pic = 0; Actually I just paste code for IPictureDispPtr pic = pfs->GetPicture() because I do not want an exception instead of error HRESULT. Bellow is an autogenerated code for GetPicture function
inline IPictureDisp * IPictureFillSymbol::GetPicture ( ) {
IPictureDisp * _result = 0;
HRESULT _hr = get_Picture(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}
C++ code works, if the map is not taken from hard drive but obtained from the same document that loaded in ArcMap. Here's the code:
esriArcMapUI::IMxDocumentPtr document(application_->Document); // application_ is the ArcMap application
esriCarto::IMapPtr mp = document->Maps->Item[0];
// the rest code is unchanged
esriCarto::IFeatureLayerPtr layer = mp->Layer[0];
esriCarto::ILegendInfoPtr inf = layer;
esriCarto::ILegendGroupPtr gr = inf->GetLegendGroup(0);
esriCarto::ILegendClassPtr cl = gr->Class[0];
esriDisplay::ISymbolPtr s = cl->Symbol;
esriDisplay::IMultiLayerFillSymbolPtr mls = s;
esriDisplay::IFillSymbolPtr fs = mls->Layer[0];
esriDisplay::IPictureFillSymbolPtr pfs = fs;
IPictureDisp * pic = 0;
HRESULT hr = pfs->get_Picture(&pic); // same code works fine
map_doc->Close();
