How to use API to replace _inp() function
When I use the _inp() and _outp() function in Win98, the application works well. But in NT workstation, it can not work. Why, and how to solve this problem? I use these two functions to read from and write to the Serial Port register.
I use these two functions as following:
unsigned char result;
unsigned short ppport = 0x2EB;
result = _inp( ppport );
_outp( ppport, (result | 0x80));
_outp( 0x2E8, 21 );
_outp( 0x2E9, 0x00 );
_outp( 0x2EB, (result & 0x7F));
Re: How to use API to replace _inp() function
The Why is because NT does not allow direct access to hardware.
The How depends on what you are trying to do with the _inp() and _outp(). If you are trying to use normal serial comms. (reading and writing characters through the serial port), check out the CreateFile() API call to create a handle to the COM port, and follow the links to see how to send and receive data. If you are trying to toggle bits in the control word, such as toggling RTS, there are some functions for doing this; EscapeCommFunction() can do some of these. Be warned, though, that toggling the lines is done at Windows' leisure, so you cannot toggle RTS quick enough for RS485 communications, for example - a problem I have.
Explain my using of the _inp() and _outp()
I use the _inp() and _outp() functions as the following( Serial Port 4 ):
unsigned char result;
unsigned short ppport = 0x2EB;
result = _inp( ppport );
_outp( ppport, (result | 0x80));
_outp( 0x2E8, 21 );
_outp( 0x2E9, 0x00 );
_outp( 0x2EB, (result & 0x7F));
Roy Wang
Re: Explain my using of the _inp() and _outp()
Oh dear. I guessed you wouldn't be doing simple communications {:v). I'm also quite certain that EscapeCommFunction() won't do what you want (although I don't know what the bits you are manipulating there are doing). This means that the only way it will work under NT is if you write a device driver (VxD or SYS). I'm afraid I can't help you there because I myself want to be able to do that, but information is thin on the ground.