Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Equivalence !

Posted on 1999-01-13
11
Medium Priority
?
294 Views
Last Modified: 2010-04-02
What's the equivalent of the function 'outportb' (Borland C++ 3.1 [DOS]) in Microsoft Visual C++ 5.0 [WINDOWS] ?
0
Comment
Question by:mike_marquet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1182048
You cannot access the hardware directly on 32bit Windows platforms, so there simply is _no_ equivalent for this function - sorry that the answer is so negative, but i all i can do is to point you to the Win9x/NT DDKs (Device Driver Kits)...
Why do you need to use 'outportb()'? Maybe we can find a way to get around this...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1182049
you could use assembler to send stuff to the ports....

asm {
  mov al, 5
  mov dl, 2h
  out dl, al
}

which would write the value 5 to port 2...

-Viktor
--Ivanov
0
 

Author Comment

by:mike_marquet
ID: 1182050
I want to access an I/O card with 8255 chips.
Can I use assembler in a window program ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:koskia
ID: 1182051
ofcourse you can use assembler,
but you must take in consideration that window handles the ports. and some other applications may also try to do the same,
in a multithreaded environment you're taking a big risk
0
 

Author Comment

by:mike_marquet
ID: 1182052
Thanks. I will try it.

0
 
LVL 86

Expert Comment

by:jkr
ID: 1182053
You may of course reject the answer, but this does _NOT_ affect the fact that it is true...
asm {
  mov al, 5
  mov dl, 2h
  out dl, al
}
-> EXCEPTION_PRIV_INSTRUCTION ;-)
0
 
LVL 2

Accepted Solution

by:
jrmcg earned 60 total points
ID: 1182054
To read and write to a port say COM 1 use this --
#include <conio.h>

UINT Port = 1016 // 3F8
int    Data = 2;
int    ReturnData;
// Write
_outp(Port, Data);

// Read
ReturnData = _inp(Port);

This is what I use.  Again you need to keep in mind that windows can still use those ports,  if you are writing to your own card just use the address of that port.  As long as you haven't installed other software that is accessing that card for one reason or another you shouldn't have any problems.

Let me know if you need further help with it..

J.R.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1182055
jkr, I just tried to give something like a pseudo code and say that the individual could use Assembler.. that's all.. I've never said that the code I wrote will work just the way it is... :))

-Viktor
--Ivanov
0
 
LVL 86

Expert Comment

by:jkr
ID: 1182056
Viktor, i agree - you can always use assembler, but certain instructions are restricted to ring 0 (i.e. kernel mode)...
0
 

Author Comment

by:mike_marquet
ID: 1182057
To JKR,

How can I set the privilege on NT to use inp(...) ?

I have try this but it doesn't work !

  BOOL             rcCode;
  HANDLE           hToken;
  TOKEN_PRIVILEGES tkp;

  rcCode = OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);
  if (rcCode == FALSE) return FALSE;

  LookupPrivilegeValue(NULL, SE_SECURITY_NAME, &tkp.Privileges[0].Luid);

  tkp.PrivilegeCount = 1; // One privileges to set
  tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

  AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);

  if (GetLastError() != ERROR_SUCCESS) return FALSE;

0
 
LVL 86

Expert Comment

by:jkr
ID: 1182058
You cannot - privileged instructions only work in ring0 (i.e. kernel mode), as i stated in my answer which you have chosen to reject ;-)
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question