阅读:1977回复:4
求助VC+MO(关于shp文件保存)
<P>我将mo自带的关于保存打点图层的方法拷贝到我的程序中,运行时出现如下错误:
EasyMapView.obj : error LNK2001: unresolved external symbol "class CString __cdecl GetFileDirectory(class CString const ;)" (<a href="mailt?GetFileDirectory@@YA?AVCString@@ABV1@@Z" target="_blank" >?GetFileDirectory@@YA?AVCString@@ABV1@@Z</A>) EasyMapView.obj : error LNK2001: unresolved external symbol "void __cdecl SetValue(class CMoFields ;,char const *,double)" (<a href="mailt?SetValue@@YAXAAVCMoFields@@PBDN@Z" target="_blank" >?SetValue@@YAXAAVCMoFields@@PBDN@Z</A>) EasyMapView.obj : error LNK2001: unresolved external symbol "void __cdecl SetValue(class CMoFields ;,char const *,char const * const)" (<a href="mailt?SetValue@@YAXAAVCMoFields@@PBDQBD@Z" target="_blank" >?SetValue@@YAXAAVCMoFields@@PBDQBD@Z</A>) EasyMapView.obj : error LNK2001: unresolved external symbol "void __cdecl SetValue(class CMoFields ;,char const *,struct IDispatch * const)" (<a href="mailt?SetValue@@YAXAAVCMoFields@@PBDQAUIDispatch@@@Z" target="_blank" >?SetValue@@YAXAAVCMoFields@@PBDQAUIDispatch@@@Z</A>) EasyMapView.obj : error LNK2001: unresolved external symbol "class CString __cdecl GetFileTitle(class CString const ;)" (<a href="mailt?GetFileTitle@@YA?AVCString@@ABV1@@Z" target="_blank" >?GetFileTitle@@YA?AVCString@@ABV1@@Z</A>) Debug/EasyMap.exe : fatal error LNK1120: 5 unresolved externals Error executing link.exe. 帮我看看啊,为什么值写不进去~ 相关程序如下: void CEasyMapView::OnFileSave() { // TOD Add your command handler code here CString filter(TEXT("ESRI Shapefiles (*.shp)|*.shp|"));</P> <P> CFileDialog dlg(FALSE, TEXT(".shp"), 0, OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, filter); if (dlg.DoModal() == IDOK) {</P> <P> m_path = dlg.GetPathName();</P> <P> // Open a new connection CMoDataConnection conn; if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection"))) return; conn.SetDatabase(GetFileDirectory(m_path)); if (!conn.Connect()) return; // Define the geodataset CMoTableDesc tableDesc; if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc"))) return; // set the field names, types, and lengths tableDesc.SetFieldCount(3); tableDesc.SetFieldName(0, TEXT("Name")); tableDesc.SetFieldType(0, moString); tableDesc.SetFieldLength(0, 16); tableDesc.SetFieldName(1, TEXT("Area")); tableDesc.SetFieldType(1, moDouble); tableDesc.SetFieldPrecision(1, 15); tableDesc.SetFieldScale(1, 3); // decimal places tableDesc.SetFieldName(2, TEXT("Perimeter")); tableDesc.SetFieldType(2, moDouble); tableDesc.SetFieldPrecision(2, 15); tableDesc.SetFieldScale(2, 3); // decimal places</P> <P> SavePoints(conn, tableDesc); } } void CEasyMapView::SavePoints(CMoDataConnection; conn, CMoTableDesc; tableDesc) { // Create a GeoDataset and associate it with a new layer // The VARIANT is needed now for the HasZ and HasM parameters for the AddGeoDataset // function which has changed since MapObjects 1.2 VARIANT va; VariantInit(;va); va.vt = VT_BOOL; va.boolVal = false;</P> <P> CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(m_path), moPoint, tableDesc, va, va)); CMoMapLayer layer; if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer"))) return; layer.SetGeoDataset(geoDataset); // Add a record for each pointgon to the GeoDataset CMoRecordset recs(layer.GetRecords()); CMoFields fields(recs.GetFields()); CString featureName; for (int i = 0; i < m_points.GetSize(); i++) { recs.AddNew(); // "Shape" = m_point SetValue(fields, TEXT("Shape"), LPDISPATCH(*m_points)); // "Name" = featureName featureName.Format("%s%d", "point", i); SetValue(fields, TEXT("Name"), featureName); // "Area" = m_point.GetArea() SetValue(fields, TEXT("Area"), 0.0); // "Perimeter" = m_point.GetPerimeter() SetValue(fields, TEXT("Perimeter"), 0.0); recs.Update(); } // Add new layer to map CMoLayers layers(m_map.GetLayers()); layers.Add(layer); ReleasePoints(); } void CEasyMapView::ReleasePoints() { for (int i = 0; i < m_points.GetSize(); i++) { m_points->ReleaseDispatch(); delete m_points; } m_points.RemoveAll(); } </P><img src="images/post/smile/dvbbs/em08.gif" /> |
|
|
1楼#
发布于:2005-05-10 09:13
<P>MapHelper.cpp,MapHelper.h,MapObjects2.h你加到工程中了吗?用之前再include一下,就应该没问题了</P>
|
|
2楼#
发布于:2005-05-10 09:00
<P>不好意思,上次没仔细看。</P><P>与上边类似的代码我在自己机器上测试过,没问题,如果你确信其余相关代码都没什么问题的话,建议你打一下Visual Studio 6.0 Server Pack6的补丁</P>
|
|
3楼#
发布于:2005-05-08 15:14
<P>编辑之前必须调用EDIT方法。</P>
|
|
4楼#
发布于:2005-05-07 21:25
GetFileDirectory(---)和 GetFileTitle(---)要自己定义的,SetValue()我的也搞不定,我现在正为这个郁闷呢
|
|