C/C++ DLL Wrapper for WSC32.DLL

//------------------------------------------
// CustomerSerial.cpp
// Trevor O Connell
//
// C/C++ DLL Wrapper for WSC32.DLL
//

#include "stdafx.h"
#include "CustomerSerial.h"
#include "wsc.h"
#include <stdio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


BEGIN_MESSAGE_MAP(CCustomerSerialApp, CWinApp)
END_MESSAGE_MAP()


CCustomerSerialApp::CCustomerSerialApp()
{
}

CCustomerSerialApp theApp;

BOOL CCustomerSerialApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}


//################################
//
// Custom Wrapper Routines by TOC
//
//################################



// Function called by first time the DLL is loaded.
void initialize()
{
}

// Called when front end stopped.
void finalize()
{
}


// Pass keycode to WSC DLL
int _SioKeyCode(const struct frontEndInterface &fx) {
  // initialize the status
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioKeyCode(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Reset/Initialize a serial port for processing
int _SioReset(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioReset(param1,1024,1024);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Clears the transmit buffer.
int _SioTxClear(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioTxClear(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Clears the transmit buffer.
int _SioRxClear(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioRxClear(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Reads the Clear to Send (CTS) modem status bit
int _SioCTS(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioCTS(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Reads the Data Carrier Detect (DCD) modem status bit
int _SioDCD(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioDCD(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
//  Reads the Data Set Ready (DSR) modem status bit.
int _SioDSR(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioDSR(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Set Baud Rate
int _SioBaud(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1, param2;
    short isNull1, isNull2;
int code;

    // get from the stack each parameter
fx.popInteger(param2, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioBaud(param1, param2);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Sets parity, stop bits, and word length.
int _SioParms(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 4 && fx.getReturnCount() == 1) {
    long param1, param2, param3, param4;
    short isNull1, isNull2, isNull3, isNull4;

int code;

    // get from the stack each parameter
fx.popInteger(param4, isNull4);
    fx.popInteger(param3, isNull3);
fx.popInteger(param2, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2 && !isNull3 && !isNull4) {

      // create the answer

code = SioParms(param1, param2, param3, param4);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Set, clear, or read Data Terminal Ready (DTR).
int _SioDTR(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1;
char param2[10];
    short isNull1, isNull2;
short len;
int code;

    // get from the stack each parameter
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioDTR(param1, param2[0]);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Set, clear, or read Data Terminal Ready (DTR).
int _SioFlow(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1;
char param2[1];
    short isNull1, isNull2;

short len;
int code;

    // get from the stack each parameter
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioFlow(param1, param2[0]);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Reads the next character from the serial line.
int _SioGetc(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioGetc(param1);

      // push the answer on the stack

      fx.pushInteger(code, 0);


    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Reads the next byte buffer from the serial line.
int _SioGets(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1, param2;
    short isNull1, isNull2;

char buffer[100];
int code;

    // get from the stack each parameter
fx.popInteger(param2, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioGets(param1, buffer, param2);

      // push the answer on the stack
 fx.pushInteger(code, 0);
      fx.pushString(buffer, strlen(buffer),0);


    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Transmit a character over a serial line.
int _SioPutc(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1;
char param2[1];
    short isNull1, isNull2;

short len;
int code;

    // get from the stack each parameter
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioPutc(param1, param2[0]);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Transmits a byte buffer over a serial line
int _SioPuts(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 3 && fx.getReturnCount() == 1) {
    long param1;
char param2[100];
long param3;

    short isNull1, isNull2, isNull3;

short len;
int code;

    // get from the stack each parameter
fx.popInteger(param3, isNull3);
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2 && !isNull3) {

      // create the answer

code = SioPuts(param1, param2, param3);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}










//--------------------------------------------
// Terminates further serial processing.
int _SioDone(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioDone(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



// Pass keycode to WSC DLL
int _SioKeyCode(const struct frontEndInterface &fx) {
  // initialize the status
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioKeyCode(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Reset/Initialize a serial port for processing
int _SioReset(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioReset(param1,1024,1024);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Clears the transmit buffer.
int _SioTxClear(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioTxClear(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Clears the transmit buffer.
int _SioRxClear(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioRxClear(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Reads the Clear to Send (CTS) modem status bit
int _SioCTS(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioCTS(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Reads the Data Carrier Detect (DCD) modem status bit
int _SioDCD(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioDCD(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
//  Reads the Data Set Ready (DSR) modem status bit.
int _SioDSR(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioDSR(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Set Baud Rate
int _SioBaud(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1, param2;
    short isNull1, isNull2;
int code;

    // get from the stack each parameter
fx.popInteger(param2, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioBaud(param1, param2);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Sets parity, stop bits, and word length.
int _SioParms(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 4 && fx.getReturnCount() == 1) {
    long param1, param2, param3, param4;
    short isNull1, isNull2, isNull3, isNull4;

int code;

    // get from the stack each parameter
fx.popInteger(param4, isNull4);
    fx.popInteger(param3, isNull3);
fx.popInteger(param2, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2 && !isNull3 && !isNull4) {

      // create the answer

code = SioParms(param1, param2, param3, param4);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Set, clear, or read Data Terminal Ready (DTR).
int _SioDTR(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1;
char param2[10];
    short isNull1, isNull2;
short len;
int code;

    // get from the stack each parameter
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioDTR(param1, param2[0]);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Set, clear, or read Data Terminal Ready (DTR).
int _SioFlow(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1;
char param2[1];
    short isNull1, isNull2;

short len;
int code;

    // get from the stack each parameter
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioFlow(param1, param2[0]);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}



//--------------------------------------------
// Reads the next character from the serial line.
int _SioGetc(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioGetc(param1);

      // push the answer on the stack

      fx.pushInteger(code, 0);


    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Reads the next byte buffer from the serial line.
int _SioGets(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1, param2;
    short isNull1, isNull2;

char buffer[100];
int code;

    // get from the stack each parameter
fx.popInteger(param2, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioGets(param1, buffer, param2);

      // push the answer on the stack
 fx.pushInteger(code, 0);
      fx.pushString(buffer, strlen(buffer),0);


    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Transmit a character over a serial line.
int _SioPutc(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 2 && fx.getReturnCount() == 1) {
    long param1;
char param2[1];
    short isNull1, isNull2;

short len;
int code;

    // get from the stack each parameter
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2) {

      // create the answer

code = SioPutc(param1, param2[0]);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}


//--------------------------------------------
// Transmits a byte buffer over a serial line
int _SioPuts(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 3 && fx.getReturnCount() == 1) {
    long param1;
char param2[100];
long param3;

    short isNull1, isNull2, isNull3;

short len;
int code;

    // get from the stack each parameter
fx.popInteger(param3, isNull3);
fx.popString(param2,len, isNull2);
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1 && !isNull2 && !isNull3) {

      // create the answer

code = SioPuts(param1, param2, param3);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

//--------------------------------------------
// Terminates further serial processing.
int _SioDone(const struct frontEndInterface &fx)
{
  short status = -1;

  // check if the in and out parameters are correct
  if (fx.getParamCount() == 1 && fx.getReturnCount() == 1) {
    long param1;
    short isNull1;
int code;

    // get from the stack each parameter
    fx.popInteger(param1, isNull1);

    // check if they are not null
    if (!isNull1) {

      // create the answer

code = SioDone(param1);

      // push the answer on the stack
      fx.pushInteger(code, 0);

    // successful -> status = 0
      status = 0;
    }
  }
  return status;
}

Comments

Popular posts from this blog

Basic Send Message to MQ with Java and IBM MQ JMS

Basic Receive Message to MQ with Java and IBM MQ JMS

Creating a simple Alert / Success Message with ASP.NET/VB using Bootstrap