Shapelib--DBFReadStringAttribute
Shapefile C Library: http://shapelib.maptools.org/
API使用:
1.SHP File API: http://shapelib.maptools.org/shp_api.html
2.Attribute (.DBF) API: http://shapelib.maptools.org/dbf_api.html
shapefile格式说明及读写代码示例: http://www.gispower.org/article/arcgis/arcother/2008/48/0848115049GB922C13K2I22H7G06A4.html
问题:
在winform(c#)中使用maptools时,在研发机上程序运行正常,在测试机上程序闪退或报错。dubug发现问题出在函数DBFReadStringAttribute。
解决方案:
在stackoverflow上找到了解决方法。
问题链接:http://stackoverflow.com/questions/11860982/msvcr71-dll-crashing-iis-7-app-pool-on-windows-server-2008-w-asp-net-4/11875302#11875302
内容引用:
Here's my original import:(原定义)
[DllImport("shapelib.dll", CharSet = CharSet.Ansi)]
public static extern string DBFReadStringAttribute (IntPtr hDBF, int iShape, int iField);
...and here's what I had to change it to:(修改后定义)
[DllImport("shapelib.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr DBFReadStringAttribute (IntPtr hDBF, int iShape, int iField);
Here's what I ended up doing in the end...
1 public static string DBFReadStringAttribute(IntPtr hDBF, int iShape, int iField) 2 { 3 IntPtr dataPtr = _DBFReadStringAttribute(hDBF, iShape, iField); 4 string output = Marshal.PtrToStringAnsi(dataPtr, 255); //255 is the supposed max length for DBF databases 5 int idx = output.IndexOf('\0'); 6 string strData; 7 if (idx > 0) 8 strData = output.Substring(0, idx).Trim(); 9 else 10 strData = ""; 11 12 return strData; 13 }
浙公网安备 33010602011771号