Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

problem in executing the C Dlls from C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kittu - 03 Jun 2005 01:42 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.