[Shapelib] C# wrapper around DBFReadIntegerAttribute.
C S
usmsci at yahoo.com
Mon Jul 9 12:52:37 PDT 2007
hi all!
i hope someone somewhere out there is or has tried to
to do some C# stuff around the C API.
i wrote a C++ program to read a SHP and DBF file and
get the attributes from a certain column and then
tried the same thing using a basic C# wrapper. most
things seem to work fine but DBFRead**Attribute stuff
just doesnt seem to work. here is my code for
re-writing the DBF struct(not headers in C#) and my
extern statement.
[StructLayout(LayoutKind.Sequential)]
public struct DBFInfo
{
public IntPtr fp;
public int nRecords;
public int nRecordLength;
public int nHeaderLength;
public int nFields;
public IntPtr panFieldOffset;
public IntPtr panFieldSize;
public IntPtr panFieldDecimals;
public string pachFieldType;
public string pszHeader;
public int nCurrentRecord;
public int bCurrentRecordModified;
public string pszCurrentRecord;
public int bNoHeader;
public int nBufSize;
};
[DllImport("shapelib.dll", EntryPoint =
"DBFReadIntegerAttribute")]
public static extern int
DBFReadIntegerAttribute(DBFInfo myDBFHandle, int
shape, int field);
i am using the shapelib.dll from the folder
shapelib(vc7.1) that i downloaded. i am using by the
way Visual Studio .NET 2003(does this make any
difference?).
then in a function i try to call this function to get
the values in a loop of all the fields.
/**************************************************
//in some function:
int shape_total = 0;
int *width = null
int *decimals = null;
int total_matches = 0;
string fieldName = "";
public static unsafe int population(IntPtr SPtr,
IntPtr DPtr, SHPInfo Shandle, DBFInfo Dhandle)
{
for(int i = 0; i < Dhandle.nFields; i++)
{
outfile.Write(DBFGetFieldInfo(Dhandle, i+1, out
fieldName, out width, out decimals));
outfile.Write(" name: ");
outfile.WriteLine(fieldName);
}
}
in my output for every field i am always getting
FTInvalid and fieldName is always blank. upon
debugging and looking at my local watches right after
i do the first DBFGetFieldInfo call here are the list
of watches under Dhandle and their values, with their
types:
bCurrentRecordModified 0 int
bNoHeader 0 int
fp 268766432 int
nBufSize 0 int
nCurrentRecord -1 int
nFields 101 int
nHeaderLength 3265 int
nRecordLength 926 int
nRecords 28 int
pachFieldType
"NNNNNNCCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNýýýý"
string
panFieldDecimals 48530680 int panFieldOffset 48521256
int
panFieldSize 48530232 int
pszCurrentRecord
"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý"
string
pszHeader "AREA" string
the number of fields, records, the header string and
record length are all correct and match up well the
C++ output i am getting in the watches their. but
notice nCurrentRecord is -1 and the decimals, offset
and pszCurrentRecord are showing crazy stuff. the
pszCurrent record in the visual studio debugging tool
is nice enough to show you ALL the fields values..in
C++ its correct, in C# i get these weird 'I'
characters. maybe because nCurrentRecord is -1
somehow?
i am at my wits end. the SHP functions work just fine.
is there anything i could try? can anyone offer any
pointers?
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting
More information about the Shapelib
mailing list