/**//* MapInfo Products Knowledge Base Product: MapX Version: 5.x Platform: Win9xNT0 Category: VC++ Code Samples Summary: Copying features and data to a new layer in VC++. Question: The following code copies all of the features in the states table, along with their data, to a new table. Answer: */ //Add the States layer m_ctrlMapX.GetLayers().Add(LPCTSTR("c:/work/c++copylayer/states.tab"), 1); //Create a variant for the layer VARIANT vLyr; vLyr.vt = VT_DISPATCH; vLyr.pdispVal = m_ctrlMapX.GetLayers().Item(LPCTSTR("STATES")); //Create a dataset for the layer m_ctrlMapX.GetDatasets().Add(miDataSetLayer,vLyr,LPCTSTR("STATES")); //midatasetlayer //reference the fields in the new dataset CMapXFields Flds; Flds = m_ctrlMapX.GetDatasets().Item(LPCTSTR("STATES")).GetFields(); //Create a variant that points to the fields collection VARIANT vFlds; vFlds.vt = VT_DISPATCH; vFlds.pdispVal = Flds.m_lpDispatch; //Create a variant that points to the features CMapXFeatures ftrs; ftrs = m_ctrlMapX.GetLayers().Item(LPCTSTR("STATES")).AllFeatures(); VARIANT vFtrs; vFtrs.vt = VT_DISPATCH; vFtrs.pdispVal = ftrs.m_lpDispatch; //Create a new LayerInfo Object CMapXLayerInfo Linfo; Linfo.CreateDispatch(Linfo.GetClsid()); //Set the Layer Info type to type: New Table Linfo.SetType(miLayerInfoTypeNewTable); //Add the parameters for the new table Linfo.AddParameter("FileSpec", COleVariant("MyNewTab.tab")); //Tab file Linfo.AddParameter("Name", COleVariant("MyNewLayer")); //Layer name Linfo.AddParameter("Fields", vFlds); //Fields Linfo.AddParameter("Features", vFtrs); //Features //Add the new layer to the map m_ctrlMapX.GetLayers().Add(Linfo.m_lpDispatch);