- GIS论坛-GIS空间站 ( http://bbs.gissky.net/Default.asp )
-- MapInfo ( http://bbs.gissky.net/ShowForum.asp?forumid=15 )
--- vc+mapx 创建新表时的错误! ( http://bbs.gissky.net/ShowPost.asp?id=43529 )
作者:vivtao
发表时间:2008-3-28 11:32:52
以下是程序中的代码: void CMyGisView::OnTest() { // TODO: Add your command handler code here //Create a new Fields Object CMapXFields Flds; Flds.CreateDispatch(Flds.GetClsid()); //Create the field definitions for the new layer. For example: //First field is a string, second is an integer, last is a date Flds.Add(1, "string");//Add(0, "My String Column"); 0->1 Flds.Add(3, "My Integer Field"); Flds.Add(2, "My Date Field"); //Create a variant that points to the fields collection just created VARIANT vFlds; vFlds.vt = VT_DISPATCH; vFlds.pdispVal = Flds.m_lpDispatch; //Create a new LayerInfo Object CMapXLayerInfo Linfo; if(!Linfo.CreateDispatch(Linfo.GetClsid())) { TRACE0("Failed to Createobject"); return; } //Set the Layer Info type to type: New Table Linfo.SetType(miLayerInfoTypeNewTable); //Add the parameters for the new table Linfo.AddParameter("FileSpec", COleVariant("c:\\Program Files\\MapInfo\\MapX 4.0\\Maps\\worldcapi.tab")); //Tab file Linfo.AddParameter("Name", COleVariant("MyNewLayer")); //Layer name Linfo.AddParameter("Fields", vFlds); //Fields
//Add the new layer to the map m_ctrlMapX.GetLayers().Add(Linfo.m_lpDispatch,1); }
当程序执行到最后一步: m_ctrlMapX.GetLayers().Add(Linfo.m_lpDispatch,1); 会弹出以下问题: Unhandled exception in MyGis.exe(MFC42.DLL):0xC0000005:Access Violation. 请高手指教,多谢了!
|