#include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "windows.h"


     typedef short _stdcall (*inpfuncPtr)(unsigned short portaddr);
     typedef void _stdcall (*oupfuncPtr)(unsigned short portaddr, unsigned char datum);
//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
/* prototype (function typedef) for DLL function Inp32: */

{
        HINSTANCE hLib;
        inpfuncPtr inp32;
        oupfuncPtr oup32;

	short data;
          /* Load the library */
     hLib = LoadLibrary("dlportio.dll");

     if (hLib == NULL) {
          printf("LoadLibrary Failed.\n");
          return -1;
     }

     /* get the address of the function */

     inp32 = (inpfuncPtr) GetProcAddress(hLib, "DlPortReadPortUshort");

     if (inp32 == NULL) {
          printf("GetProcAddress for inport Failed.\n");
          return -1;
     } 


     oup32 = (oupfuncPtr) GetProcAddress(hLib, "DlPortWritePortUshort");

     if (oup32 == NULL) {
          printf("GetProcAddress for Oupport Failed.\n");
          return -1;
     }
     printf("Vse je OK.\n");

	if(argc<2)
	{
		printf("Usage\n\n");
		printf("partest1.exe ,,\n\n\n");
		return 0;
	}

	if(!strcmp(argv[1],"read"))
	{
		data = (inp32)(atoi(argv[2]));
		printf("Data read from parallel port is  ");
		printf("%d\n\n\n\n",data);
	}

	if(!strcmp(argv[1],"write"))
	{
		(oup32)(atoi(argv[2]),atoi(argv[3]));
		printf("Data written to parallel port is  ");
		printf("%s\n\n\n\n\n",argv[3]);
	}

	return 0;
}

//---------------------------------------------------------------------------
