Community articleSetting Up Your Application
Added by IBM contributorIBM on May 3, 2012
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.



  1. A set of template project files for applications have been provided for you. Copy the Form template files into the directory in which you will be building your application.
    • Files that are compatible with the Visual C++ development environment can be found in: < API Program folder
       
      \Samples\Msc32\Form\Template.
    • If you prefer to set up the application development environment yourself, follow the procedure outlined in Setting up the C environment to use the Form library .
  2. Create a new .c source file named calculateAge.c and include any necessary header files. For every application that uses the Form Library, you must include pe_api.h. In calculateAge.c:
  3.    #include "pe_api.h"
       #include <stdio.h>
       #include <string.h>
       #include <stdlib.h>


    Note: You must always include pe_api.h in any source file that uses the API.
  4. Declare all the functions implemented in calculateAge.c.
    • The initialize function initializes the API.
    •    r_short initialize(
         #ifdef PROTO
            void
         #endif
         );

    • The loadForm function calls the API function UFLReadForm that will read a specified form into memory.
    •    r_short loadForm(
         #ifdef PROTO
            formNodeP *form
         #endif
         );

    • The function getBirthDate uses the API function UFLGetLiteralByRefEx to retrieve date information from the form loaded in memory.
    •    r_short getBirthDate(
         #ifdef PROTO
            formNodeP form,
            int *birYear,
            int *birMonth,
            int *birDay
         #endif
         );

    • The saveForm function saves the form to disk by calling the API function UFLWriteForm.
    •    r_short saveForm(
         #ifdef PROTO
            formNodeP form
         #endif
         );

    • The reportError function reports errors by printing the error codes associated with a particular error.
    •    void reportError(
         #ifdef PROTO
            char *theMessage,
            r_short theCode
         #endif
         );

  5. Create your main function and declare any variables needed for your application. The main function in calculateAge.c will declare variables for the birth day, birth month, and birth year. It will also be responsible for calling the functions declared previously. Finally, main is responsible for freeing any memory used by the application by making a call to the function UFLDestroy.
  6.    #ifdef WINDOWS
       #ifndef OLD_STYLE_PARAMS
          int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR
          lpszCmdParam, int nCmdShow)
       #else
          int PASCAL WinMain(hInstance, hPrevInstance,lpszCmdParam, nCmdShow)
          HANDLE hInstance;
          HANDLE hPrevInstance;
          LPSTR lpszCmdParam;
          int nCmdShow;
       #endif
     
       #else
       #ifndef OLD_STYLE_PARAMS
          int main(int argc, char **argv)
       #else
          int main(argc, argv)
          int argc;
          char **argv;
       #endif
       #endif
       {
       formNodeP theForm;
       int birthYear;
       int birthMonth;
       int birthDay;
       #ifndef WINDOWS
          void *hInstance = NULL;
       #else
       #ifndef MSC
       #ifndef __FLAT__
          _InitEasyWin();
       #endif
       #endif
       #endif
     
    /* First, we call a function that will initialize the special memory and 
          error handling. */
     
          if (initialize((void *)hInstance) != OK)
          {
             reportError("Error in initialize function.\n", 0);
             exit (1);
          }
     
    /* Next, we call a function that will load the form into memory. */
     
          if (loadForm(&theForm) != OK)
          {
             reportError("Error in loadForm function.\n", 0);
             exit (1);
          }
     
    /* This function retrieves the birth year, month and day values (as
          integers) from the original form. */
     
          if (getBirthDate(theForm, &birthYear, &birthMonth, &birthDay) != OK)
          {
             reportError("Error in the getBirthDate function.\n", 0);
             exit (1);
          }
     
    /* This function writes the birth year, month, and day into hidden fields
          in the original form whose values are the arguments for the compute for
          PAGE1.SHOWAGE.value */
     
          if (setBirthDate(theForm, birthYear, birthMonth, birthDay) != OK)
          {
             reportError("Error in the setBirthDate function.\n", 0);
             exit (1);
          }
     
    /* This function saves the processed form in the current directory as
          'output.xfd'. */
     
          if (saveForm(theForm) != OK)
          {
             reportError("Error in the saveForm function.\n", 0);
             exit (1);
          }
     
    /* Now that we are done with the form, we can free the memory by calling
          UFLDestroy. The parameter, 'theForm', is a pointer to the root node of
          the form. This causes the root node and all of its children (the
          complete form) to be deleted from memory. */
     
          UFLDestroy(theForm);
          return(OK);
       }


Related tasks