Quantcast
Channel: Morovia Knowledge Base
Viewing all articles
Browse latest Browse all 128

Example: Calling PDF417 Encoder DLL (version 4) in C

$
0
0

Example: Calling PDF417 Encoder DLL (version 4) in C

SUMMARY

when PDF417 Fontware & Writer SDK 4.0 was released in Oct. 2009, it did not include an example for C langauge. This article contains the source code to demonstrate calling encoder DLL in C.

SOURCE CODE

To call Windows dll in C, first loads the dll to memory and obtain a handle to the module. Subsequently call GetProcAddress to receive the address of the function. The convert the pointer to the function pointer. After the function pointer is obtained, invoke the function.

#include <windows.h>
#include <stdio.h>

/* This code demonstrates calling PDF417FontEncoder4.dll from C.
 * Note that 64-bit DLL should be called if the EXE is 64-bit.
 */

/** Functions prototypes exported from DLL */
typedef int (__stdcall *PDF417Encode_FUNC)(const char* dataToEncode,
  int numRows, int numCols,
  int securityLevel, int fullPDF,
  double aspectRatio, double yHeight,
  void** ppResult);

typedef int (__stdcall *PDF417BarStr_FUNC)(void* pResult,
  char* buffer,
  int* maxSize,
  const char* eol);

typedef void (__stdcall *PDF417Destroy_Func)(void* pResult);


int main(int argc, char* argv[])
{
  HINSTANCE hInstance;
  PDF417Encode_FUNC encoder_func;
  PDF417BarStr_FUNC barstr_func;
  PDF417Destroy_Func destroy_func;
  const char* data = "data to encode. put something here.";
  void* pResult = NULL;
  int rc = 0;

  char buffer[8096];
  int maxsize = 8096;

  /* load the DLL and save the handle */
  hInstance = LoadLibraryW(L"MoroviaPDF417FontEncoder4.dll");
  if (!hInstance) {
    printf("The DLL is not found.\n");
    return 1;
  }

  /* locate address of each function */
  encoder_func = (PDF417Encode_FUNC)GetProcAddress(hInstance,
    "PDF417Encode");
  barstr_func = (PDF417BarStr_FUNC)GetProcAddress(hInstance,
      "PDF417ResultGetBarcodeString");
  destroy_func = (PDF417Destroy_Func)GetProcAddress(hInstance,
      "DestroyPDF417EncodeResult");
  if (!encoder_func || !barstr_func || !destroy_func) {
    printf("Incorrect DLL.\n");
    return 2;
  }

  /* perform the actual encoding */
  rc = (*encoder_func)(data,
            14, /* rows */
            10, /* cols */
            5,  /* minimum security level */
            1,  /* full PDF417 */
            0.0,  /* aspect ratio - auto */
            6.2,  /* for MRV PDF417 N6 font. If a different font is
                chosen, change the value accordingly */
            &pResult);
  if (rc !=0 ) {
    printf("Error in encoding (%d).\n", rc);
    return 3;
  }

  /* Retrieve the barcode string */
  rc = (*barstr_func)(pResult, buffer, &maxsize, "\r\n");
  printf("Barcode String is \n%s\n", buffer);

  /* Unload the DLL if no longer required. */
  FreeLibrary(hInstance);
  return 0;
}

APPLIES TO

  • PDF417 Fontware & Writer SDK 4


Viewing all articles
Browse latest Browse all 128

Trending Articles