Solved

Parallel Port access with C#

Posted on 2004-05-01
6
426 Views
Last Modified: 2012-06-27
I'm looking for some help on writing to the parallel port within WinXP Pro using C#.  I'm not sure how this is done and I can't find any substantial resources online.  All I want to do is be able to write a byte, that's it, nothing else.

Thanks
0
Comment
Question by:ChaveTech
6 Comments
 
LVL 5

Expert Comment

by:jjacksn
ID: 10969965
This should do it:

http://www.codeproject.com/csharp/csppleds.asp?df=100&forumid=21021&exp=0&select=799135

In addition, you could always write it in a C++ com and interop to it.
0
 

Author Comment

by:ChaveTech
ID: 10970057
I've been to that site and have tried it, but it's not working.  I don't know if the DLL the author provides is valid.  I don't have a problem writing it in C++, but I'm not familiar with writing in COM.  Do you have any suggestions?
0
 
LVL 9

Expert Comment

by:glsac
ID: 10970199
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 5

Expert Comment

by:jjacksn
ID: 10970873
ChaveTech,

With com, all you need to do is create an ATL com object.  Use the template.  Add a method called to the COM interface you create called WriteParallelByte which takes in a byte (as an int).  You can then simply include this in a C# project by adding a reference to the COM object (dll).  .NET Studio will then automatically create an interop dll that will allow you to instantiate this com object and make the call.
0
 
LVL 4

Accepted Solution

by:
philippe_leybaert earned 500 total points
ID: 11003906
If you just want to write some bytes or text to the parallel port, you can create an output file stream that maps to the parallel port:

The drawback is that you need to call unmanaged code from kernel32.dll

class myClass
{            
   [DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
   private static extern IntPtr CreateFile(
                    string lpFileName,
                    [MarshalAs(UnmanagedType.U4)] uint dwDesiredAccess,
                    [MarshalAs(UnmanagedType.U4)] int dwShareMode,
                    [MarshalAs(UnmanagedType.U4)] uint lpSecurityAttributes,
                    [MarshalAs(UnmanagedType.U4)] int dwCreationAttributes,
                    [MarshalAs(UnmanagedType.U4)] int dwFlagsAndAttributes,
                    IntPtr hTemplateFile
                   );

   public FileStream createLPT1_FS()
   {
      IntPtr h = CreateFile("LPT1",0xC0000000,0,0,3,0,(IntPtr)0);

      return new FileStream(h,FileAccess.ReadWrite);
   }
}
0
 
LVL 5

Expert Comment

by:jjacksn
ID: 11006866
Windows knows how to Map files like this?  I had no idea....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now