Sample programs for using outbound API function calls

A sample setup for the OUTBOUNDMAPPER API call is shown below:

int ret, iarg;
char **argpp;
char *argp[12];
argp[0] = "OUTBOUNDMAPPER";
argp[1] = "EDIFILE"; /* full EDI output file name */
argp[2] = "837MAP"; /* file name of initial map */
argp[3] = "PO"; /* transaction code */
argp[4] = "-t"; /* message/transaction set parameter */
argp[5] = "837"; /* message/transaction  set */
argp[6] = "-dt"; /* trading partner directory parameter */
argp[7] = "../tptner"; /* trading partner directory */
argp[8] = "-dg"; /* generated files directory
						 parameter */
argp[9] = "../rtp"; /* generated files (ie. map)
						 directory */
argp[10] = "-st"; /* trading partner DSN parameter */
argp[11] = "MS Access";   /* trading partner DSN */
iarg = 12 ;
argpp = &argp[0];ret  = OUTBOUNDMAPPER(iarg, argpp);

A sample setup for the OUTBOUNDRunCmd API call is shown below:

 int ret;ret = OUTBOUNDRunCmd("EDIFILE 837MAP PO -t 837 –dt ../tptner –dg ../rtp”);

A sample setup for the OUTRun API call is shown below:

// memiodemo.cpp 
// This is a memory I/O demo program. This is an example
// of an OUTRun call where the input file and output 
// file are both memory files.  Thisprogram illustrates 
// how to call a map and have that map read a file
// from memory instead of disk.  It also illustrates how 
// to call a map so that the map will write a file to
// memory instead of disk. // The construction of second 
// parameter, the MEMIOSTRUCT, is the key to passing
// memory files.  The run map switches are passed in as
// the first parameter.
#include <windows.h>
#include <stdio.h>
/* Memory file structure */
typedef struct {
	char *filename;   /* Pointer to name of Directory\Filename - in MAP File */
	char **paddr;     /* Double pointer to memory address 
							of data */
	long *pbytes;     /* Pointer to Number of bytes of 
							data in memory */
	long *pbuflen;    /* Pointer to Number of bytes 
							allocated in memory */
} MEMIOSTRUCT

extern "C" { 
__declspec (dllimport) int WINAPI OUTRun(LPSTR, MEMIOSTRUCT **);
}
int main(int argc, char* argv[])
{
   int ret;
char myfile1[100], myfile2[100];
   char *membuf1, membuf2;
   long membytes1, membytes2;
 long membuflen1, membuflen2;
   FILE *fp;
MEMIOSTRUCT mystruct, mystruct2;	
MEMIOSTRUCT *ppmystruct[3];
ppmystruct[0] = &mystruct; 
ppmystruct[[1] = &mystruct2;	
ppmystruct[2] = (MEMIOSTRUCT *)NULL; /* Must be terminated with a NULL pointer */

   /* Allocate memory for the map input file */ 
	if((membuf1 = (char *)malloc(100000 * sizeof(char)))
					 == NULL 
)      exit( 1 );
   /* Load data into the memory */
   if( (fp = 	fopen("d:\\tmp\\850out\\data\\
		850_udf.txt", "rb" )) == NULL
)
   {	
 	exit(1);
   }
 	else
   {
	int i = 0;
	char ch;
	  while((ch = fgetc(fp)) != EOF)
	membuf1[i++] = ch;
	  if(ch == EOF) membuf1[i + 1] = '\0';
	  fclose( fp );
   }
   /* Find the number of bytes of valid data */
   membytes1 = strlen(membuf1);	
/* The directory and file name are exactly the same as in the map(case sensitive) */
   strcpy(myfile1, "c:\\test\\data\\850_udf.txt");
	ppmystruct[0]->filename = myfile1;
	ppmystruct[0]->paddr = &membuf1;
	ppmystruct[0]->pbytes = &membytes1;
 	ppmystruct[0]->pbuflen= &membuflen1;
/* Set up the MEMIOSTRUCT parameters for the Output memory File */
/* The directory and file name are exactly the same as in the map(case sensitive) */
   strcpy(myfile2, "c:\\test\\data\\850_out.txt");
	ppmystruct[1]->filename = myfile2;
/* For files that are being written to, one can set the 
 base char pointerto null, and ECRTP will allocate space for any output data and place the address of the allocated space in membuf2. Similarly, if the output memory was preallocated and the ECRTP needed more space, the ECRTP would reallocate the space and place any modified memory address back in membuf2. */
 
membuf2 = (char *) NULL;

ppmystruct[1]->paddr = &membuf2;
/* set number bytes to output memory written to 0 */
/* Note, if one is starting with allocated space, the new output would be appended at the value of membytes2 */

membytes2 = 0L;

ppmystruct[1]->pbytes = &membytes2;

/* Set the number of bytes already allocated for the output file to zero */

ppmystruct[1]->pbuflen= &membuflen2;

 /* The run map switches are passed in as one parameter argv[1] */	

ret = OUTRun(argv[1], ppmystruct);

 free membuf1;  /* free input file buffer */

 /* Note at this point if the map wrote any data to the output file,  then membuf2 will point to the memory that was allocated, membytes2 will contain the number of bytes written.  */

/* it is the user’s responsibility to free the output file */

if(membuf2 != (char *) NULL)
	free(membuf2);			return ret;
}