main.cpp
上传用户:seepec
上传日期:2020-01-16
资源大小:183k
文件大小:1k
源码类别:

并口编程

开发平台:

C/C++

  1. #include <windows.h>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "stdafx.h"
  7. //#include "lib_victorcoasne_com.hpp"
  8. using namespace std;
  9. typedef short _stdcall ( * InputProcedure )( short ); 
  10. typedef short _stdcall ( * OutputProcedure )( short, short ); 
  11. //short _stdcall Inp32(short PortAddress); 
  12. //void _stdcall Out32(short PortAddress, short data);
  13. int main( void )
  14. {
  15.       HMODULE library = LoadLibrary( "inpout32.dll" );
  16.       if( library )
  17.       {
  18.             InputProcedure Inp32 = ( InputProcedure )GetProcAddress( library, "Inp32" );
  19.             OutputProcedure Out32 = ( OutputProcedure )GetProcAddress( library, "Out32" );
  20.             if( Inp32 && Out32 )
  21.             {                
  22.                   short OutputVal=0;
  23.                   cout<<"Input the data:";
  24.                   cin>>OutputVal;
  25.                   Out32( 0x378, OutputVal );
  26.                   short PortVal = Inp32( 0x378 );
  27.                   cout << "recieved from port: " << PortVal << endl;
  28.             }
  29.             else
  30.             {
  31.                   cerr << "GetProcAddress failed" << endl;
  32.             }
  33.             FreeLibrary( library );
  34.       }
  35.       else
  36.       {
  37.             cerr << "LoadLibrary failed" << endl;
  38.       }
  39.       system("pause");
  40.       return 0;
  41.       
  42. }