473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

incorrect code

The following code is not working.it gives the same error messege as it gives when program specified for win95/98 is run.


Expand|Select|Wrap|Line Numbers
  1.  #include <stdio.h>
  2. #include <conio.h>
  3. #include <windows.h>
  4. #include <string.h>
  5. #include <io.h>
  6. #include <stdafx.h>
  7. #include <windows.h>
  8. #include <windowsx.h>
  9. #include <oleauto.h>
  10. #include "stdafx.h"
  11. #include "stdio.h"
  12. #include "string.h"
  13. #include "stdlib.h"
  14.  
  15.  
  16. // C RunTime Header Files
  17.  
  18. #include <malloc.h>
  19. #include <memory.h>
  20. #include <tchar.h>
  21.  
  22.  
  23.  
  24. /* Definitions in the build of inpout32.dll are:            */
  25. /*   short _stdcall Inp32(short PortAddress);               */
  26. /*   void _stdcall Out32(short PortAddress, short data);    */
  27.  
  28. /* prototype (function typedef) for DLL function Inp32: */
  29.  
  30.      typedef short (_stdcall *inpfuncPtr)(short portaddr);
  31.      typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
  32.  
  33. #define PPORT_BASE 0x378
  34.  
  35.  
  36. // Prototypes for Test functions
  37. void test_read8(void);
  38. void test_write(void);
  39. void test_write_datum(short datum);
  40.  
  41.  
  42. /* After successful initialization, these 2 variables
  43.    will contain function pointers.
  44.  */
  45.      inpfuncPtr inp32fp;
  46.      oupfuncPtr oup32fp;
  47.  
  48.  
  49. /* Wrapper functions for the function pointers
  50.     - call these functions to perform I/O.
  51.  */
  52.      short  Inp32 (short portaddr)
  53.      {
  54.           return (inp32fp)(portaddr);
  55.      }
  56.  
  57.      void  Out32 (short portaddr, short datum)
  58.      {
  59.           (oup32fp)(portaddr,datum);
  60.      } 
  61.  
  62.  
  63. int main(void)
  64. {
  65.      HINSTANCE hLib;
  66.  
  67.  
  68.  
  69.      /* Load the library */
  70.      hLib = LoadLibrary(TEXT("inpout32.dll"));
  71.  
  72.      if (hLib == NULL) {
  73.           fprintf(stderr,"LoadLibrary Failed.\n");
  74.           return -1;
  75.      }
  76.  
  77.      /* get the address of the function */
  78.  
  79.      inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
  80.  
  81.      if (inp32fp == NULL) {
  82.           fprintf(stderr,"GetProcAddress for Inp32 Failed.\n");
  83.           return -1;
  84.      }
  85.  
  86.  
  87.      oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
  88.  
  89.      if (oup32fp == NULL) {
  90.           fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
  91.           return -1;
  92.      }
  93.  
  94.  
  95. /*******************************************************/
  96. /** IF WE REACHED HERE, INITIALIZED SUCCESSFUL    ******/
  97. /*******************************************************/
  98.  
  99.      /* now test the functions */
  100.  
  101.  
  102.      /***** Read 8 bytes at I/O base address */
  103.      test_read8();
  104.  
  105.  
  106.      /*****  Write 0x75 to data register and verify */
  107.      test_write();
  108.  
  109.  
  110.  
  111.      /*****  One more time, different value */
  112.      test_write_datum(0xAA);
  113.  
  114.  
  115.      /* finished - unload library and exit */
  116.      FreeLibrary(hLib);
  117.      return 0;
  118. }
  119.  
  120. /*
  121.    TEST:  Read inputs of 8 registers from PORT_BASE address
  122.  */
  123. void test_read8(void) {
  124.  
  125.      short x;
  126.      int i;
  127.  
  128.      /* Try to read 0x378..0x37F, LPT1:  */
  129.  
  130.      for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) {
  131.  
  132.           x = Inp32(i);
  133.  
  134.           printf("Port read (%04X)= %04X\n",i,x);
  135.      }
  136.  
  137. }
  138.  
  139. /*
  140.    TEST:  Write constant 0x77 to PORT_BASE (Data register)
  141.  */
  142. void test_write(void) {
  143.      short x;
  144.      int i;
  145.  
  146.      /*****  Write the data register */
  147.  
  148.      i=PPORT_BASE;
  149.      x=0x75;
  150.  
  151.      /*****  Write the data register */
  152.      Out32(i,x);
  153.  
  154.      printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
  155.  
  156.      /***** And read back to verify  */
  157.      x = Inp32(i);
  158.      printf("Port read (%04X)= %04X\n",i,x);
  159.  
  160.  
  161.      /*****  Set all bits high */
  162.      x=0xFF;
  163.      Out32(i,x);
  164.  
  165.      /*****  Now, set bi-directional and read again */
  166.      Out32(PPORT_BASE+2,0x20);     // Activate bi-directional
  167.      x = Inp32(i);
  168.      printf("Set Input, read (%04X)= %04X\n",i,x);
  169.  
  170.      Out32(PPORT_BASE+2,0x00);     // Set Output-only again
  171.      x = Inp32(i);
  172.      printf("Reset Ouput, read (%04X)= %04X\n",i,x);
  173.  
  174.  
  175. }
  176.  
  177. /*
  178.    TEST:  Write data from parameter
  179.  */
  180. void test_write_datum(short datum) {
  181.      short x;
  182.      int i;
  183.  
  184.      i=PPORT_BASE;
  185.      x = datum;
  186.  
  187.      /*****  Write the data register */
  188.      Out32(i,x);
  189.  
  190.      printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
  191.  
  192.      /***** And read back to verify  */
  193.      x = Inp32(i);
  194.      printf("Port read (%04X)= %04X\n",i,x);
  195. }
Aug 1 '07 #1
1 2138
JosAH
11,448 Expert 8TB
The following code is not working.it gives the same error messege as it gives when program specified for win95/98 is run.
Too bad; sadly enough we're not all psychic so could you please elaborate a bit
on *what* the error is exactly? And *what* did you expect it to do? Please help
us to help you.

kind regards,

Jos

ps. I also changed your topic title ("hi" was not a very informative title)
Aug 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Yogesh Khanolkar | last post by:
Hi, I am getting incorrect o/p from the code below: #include<stdio.h> #include<float.h> #include<limits.h> main() { double val,val1;
2
by: Linda Wienholt | last post by:
I have two usercontrols on the home page of my website. They are intermitently sending incorrect HTML to the browser, which results in a textbox being rendered with the wrong width. Either both...
1
by: murphy | last post by:
Hi, I've been seeing two symptoms with my asp.net site that have started recently after a long period of smooth running. As others on our team make changes to referenced dll's I find that I get...
3
by: murphy | last post by:
Hi, I've been seeing two symptoms with my asp.net site that have started recently after a long period of smooth running. As others on our team make changes to referenced dll's I find that I...
4
by: Peter Ritchie | last post by:
Does anyone know how to suppress a specific warning for a line or block of code in C#? C++ has a nice facility to disable a warning for a block of code with #pragma for warnings that are incorrect...
2
by: mankolele | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Simple Database Connection</title> </head> <body bgcolor="white"> <?php $connection =...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
1
by: zandrew | last post by:
Hello there everyone. For a summer project I'm doing, I have to use a phone to pass an image I've taken (on the phone) to a dedicated server I've made on a local ubuntu machine. For the upload code,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.