Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to write to Parallel Port causes exception

Posted on 2004-08-23
12
Medium Priority
?
222 Views
Last Modified: 2013-11-20
I have some code that writes to a parallel port.  I have used both the C++ _outp and the InPOut32 dll.  Whenever accessing parallel port to begin output, I get a 0xc0000005 exception which I believe is an access denied.  If anyone has seen this, and can give me some advice, that would be great.

Thanks,

Matt
0
Comment
Question by:neverrealm
[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
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11872952
This is an Access Violation, meaning that your code uses invalid memory addresses. Could you post your code?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11873083
I have used the WinIO library (www.internals.com) with success, take a look to previous question:

http:/Dot_Net/VisualC_PLUS_PLUS_DOT_NET/Q_21045309.html

Be carefull when generating the drivers, all must reside on the same folder of your app, and you must run the app from the Windows Explorer to make app's directory to be the active directory.

0
 

Author Comment

by:neverrealm
ID: 11873179
I think I may have figured out a way around this.  Do either of you guys know how to execute command line calls via VC++
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.

 
LVL 86

Expert Comment

by:jkr
ID: 11873213
You mean like

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                           msg;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_HIDE;

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                   &pi.hProcess,
                                                                   FALSE,
                                                                   INFINITE,
                                                                   QS_ALLINPUT
                                                               )
           )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);
}

and call that like

ExecuteAndWaitForCompletion ( "ping.exe 192.168.0.1");

?

You could also use 'system()', but that pops up a console window.

WinExec( "ping.exe 192.168.0.1", SW_HIDE);

will work also if you don't have to wait for the command to finish.
0
 

Author Comment

by:neverrealm
ID: 11873763
Ok, the WinExec thing is exactly what I'm looking for, but it always comes up with a file_not_found error on copy C:\BarFile\label.bar LPT1.  I can type the same thing into the command line and it will print.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11873833
you have to execute the "command prompt", something like:

WinExec( "cmd copy c:\\BarFile\\label.bar LPT1:");
0
 

Author Comment

by:neverrealm
ID: 11874095
Ok, that cured the file not found error in some instances, but it's still not performing the command, i.e., printing to LPT1
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11874128
Questions:
Are you writting "LPT1" or "LPT1:"
Is your printer actually connected to LPT1?
Is your printer enabled to work with DOS?
0
 

Author Comment

by:neverrealm
ID: 11891267
I tried both LPT1 and LPT1: and neither worked.  When I do a copy from the command prompt it works fine doing this:   copy c:\barfile\label.bar LPT1
0
 

Author Comment

by:neverrealm
ID: 11907943
I solved the problem.  I used a handle to the LPT1 port and wrote to the port the same way as with COM ports, without setting the state.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12233587
PAQed, with points refunded (200)

Computer101
E-E Admin
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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