pointers and parallel ports

DeproG
DeproG used Ask the Experts™
on
Is there any way to set the address for a pointer like this for example:  
{
int *mypointer;
mypointer = 0x0378;
}

I figured you might be able to manipulate say a led connected to the parallel port if I could just get this working. I've checked around the net and found that there should be functions called out/inp or outportb/inportb but those functions don't exist in my conio.h that come with Dev-C++ 5.

Any ideas?
Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
For direct pointer setup try following code:
int *mypointer;
mypointer = (int *)0x0378;

If you are programming under Win32, port input and output function are locked for this mode. In order to perform communication through varianous communication functions like TransmitCommChar and WaitCommEvent. With CreateFile function it is possible to open port for communication.
C++Builder help describes how to open communication port:
<i>Communications Resources
The CreateFile function can create a handle to a communications resource, such as the serial port COM1. For communications resources, the dwCreationDistribution parameter must be OPEN_EXISTING, and the hTemplate parameter must be NULL. Read, write, or read-write access can be specified, and the handle can be opened for overlapped I/O.
A communications resource is a physical or logical device that provides a single bidirectional, asynchronous data stream. Serial ports, parallel ports, fax machines, and modems are examples of communications resources. For each communications resource, there is a service provider, consisting of a library or driver, that enables applications to access the resource.</i>

For DOS programs you can use inline assembly insertion, which allows executing input and output port operations.
Example of assembly command which is used with 'asm' directive:
in al, dx
in al, 220h
out dx, al

Commented:
i tried the code below on Dev-C++ 4.9.6.0 and it worked at least for win98se.

unsigned short port ;
unsigned char value ;

int main(int argc, char *argv[])
{
  port = 0x378 ;
  value = 0xFF ;
 
    // write 0xFF to parallel-port
  __asm ("movw _port, %dx") ;
  __asm ("movb _value, %al") ;
  __asm ("outb %al, %dx") ;
 
  system("PAUSE") ;    
  return 0 ;
}

Commented:
But Zanuda is right: this code surely won't work with win2000/nt/xp, because these have more restrictions on direct system access.
btw: pointers and ports mean different things: a pointer points to a memory location and ports are used to access external devices (eg. system timer, hard disk, ..).
the pc makes a difference here, but there are also systems, which map the io into the memory.

Commented:
This question didn't show any activity for more than 21 days. I will ask Community Support to close it unless you finalize it yourself within 7 days.
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity,  I will suggest to accept

    "Zanuda"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
========
Werner
Force accepted

** Mindphaser - Community Support Moderator **

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial