Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a DLL from VFP 2

Status
Not open for further replies.

FoxIPO

Programmer
Feb 9, 2007
22
US
Hi,

I'm trying to call a DLL that is a USPS encoder for producing a Intelligent Mail Barcode. They gave me the DLL and a C example but I can't seem to figure out how to translate the C code into VFP code.
Here's a partial listing of the C code:
Code:
char TrackString[21];
char RouteString[12];
char BarString[66];
int RetCode;

int USPS4CB( char *TrackPtr, char *RoutePtr, char *BarPtr); 
memcpy(TrackString,"53379777234994544928",20);
TrackString[20] = '\0';
memcpy(RouteString,"51135759461",11);
RouteString[11] = '\0';
memset(BarString, ' ', sizeof(BarString));	/* Prime blanks!  	*/
BarString[65] = '\0';			/* Set null		*/

RetCode = USPS4CB(TrackString,RouteString,BarString);

printf("Outputs are: \n");
printf("USPS4CB RetCode is: %i\n",RetCode);
printf("Encoded Bar String is: %s\n",BarString);

What I am looking for is the declaration and calling syntax, basically reproducing the above in VFP. It will be a huge help if someone can get me pointed in the right direction on this.

Thanks.
 
some pointers (although that's more of a C concept ;-):

DECLARE helps you declaring a DLL function in VFP.

In this case it seems there is a USPS4CB function you want to use, which takes three char pointers (adresses of char variables).

looks like:

Code:
DECLARE USPS4CB string TrackPtr, string RoutePtr, string BarPtr In d:\path\to\ups.dll

Local lcTrack, lcRoute, lcBar
lcTrack = "53379777234994544928"+chr(0)
lcRoute = "51135759461"+chr(0)

lcBar = space(65)+chr(0)

RetCode = USPS4CB(lcTrack,lcRoute,@lcBar)
? "Return Code:",RetCode
? "Bar:", lcBar

Just replace the path and name to the UPS.DLL in the DECLARE.

Bye Olaf.
 
Thanks Olaf,

I first tried copying and pasting your code but I got a syntax error on the declare statement so I changed it slightly to the below and it worked!
Code:
DECLARE USPS4CB  In d:\source\ivptest\usps4cb.dll string TrackPtr, string RoutePtr, string BarPtr

Thanks so much, that's worth at least a gold medal [medal] plus a star.
 
Ah yes, in some cases the order of clauses is important. Thanks for posting back.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top