hello group,
i'm tyrying to call into a C Dlls and unable to get the results properly
after getting executed the functions.
I'm providing with all the code part:
C API function :
int PBFNGetZipList(
char *zipExpr,
int count,
pDbxSearchDataDef *returnData);
• zipExpr: The ZIP code search criteria can be any one to five-digit number.
For
example, 605 returns all ZIP codes starting with 605 including 60515, 60516.
In
another example, 60 returns all ZIP codes beginning with 60.
• count: The maximum number of results to be returned.
• returnData: returnData is a pointer to a data structure of type
dbxSearchDataDef.
Returns a list of ZIP codes (i.e., 60501, 60504, 60599) that match the
search criteria.
The dbxSearchDataDef C structure contains return address information. The
dbxSearchDataDef structure is shown next.
typedef struct dbxSearchDataDefinition
{
char zipcode[6];
char cityName[29];
char countyName[26];
char stateAbbreviation[3];
} dbxSearchDataDef, * pDbxSearchDataDef;
My C# code here:
API function prototype declaration in C#
[DllImport("PBFN",CharSet=CharSet.Ansi)]
public static extern int PBFNGetZipList(
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder zipExpr,
int count,
ref PBFNSearchDataDefinition returnData1);
structure definition:
[ StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct PBFNSearchDataDefinition
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=6)]
public String zipcode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=29)]
public String cityName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=26)]
public String countyName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=3)]
public String stateAbbreviation;
}
Calling the function:
StringBuilder zip = new StringBuilder();
zip.Append("605");
int count= 2;
int getcity = 0;
getcity = PBFNGetZipList(zip,count,ref searchcities);
getcity should return the value with the data updated to the structure
searchcities.
I tried with different options like stringbuilder,String type , but couldn't
find exact solution. Can any one tell me What
the changes i have to make in my code.
Thanks in Advance.
Regards,
kittu.
kittu - 03 Jun 2005 16:37 GMT
hi group,
I'm able to execute it but getting some junk return types which is not valid.
C# function prototype declaration:
[DllImport("PBFN",CharSet=CharSet.Ansi)]
public static extern int PBFNGetZipList(
[MarshalAs(UnmanagedType.LPStr)]
ref String zipExpr,
int count,
ref pDbxSearchDataDef returnData1);
String ziplist = 605";
int count= 1;
int getcity = PBFNGetZipList(ref ziplist,count,ref searchcities);
The function is returning the value 0 which is not the correct one.
It must return a no. upto max the integer count value.
the original C Dll provided to me:
int PBFNGetZipList(char *zipExpr,
int count,
pDbxSearchDataDef *returnData);
plz help me out with the code.
I would be grateful if u can give me any suggestions.
thanks,
kittu