CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2004
    Location
    Pakistan(Skardu)
    Posts
    64

    Arrow write data on LPT Port using win32

    hi,
    i want to write data on printer port ,have any cammand that do that.
    the data may be 0 or 1
    Thanx

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: write data on LPT Port using win32

    Use CreateFile to open your LPT device as described under communication resources. Instead of "COM1" just open "LPT1". If you have any further questions, feel free to ask again.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Jan 2006
    Posts
    35

    Re: write data on LPT Port using win32

    Does CreateFile work with NT,2000,XP?

  4. #4
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: write data on LPT Port using win32

    Quote Originally Posted by eeboy
    Does CreateFile work with NT,2000,XP?
    yep it does

    regards
    sreehari

  5. #5
    Join Date
    May 2005
    Posts
    399

    Re: write data on LPT Port using win32

    Quote Originally Posted by eeboy
    Does CreateFile work with NT,2000,XP?
    To know what operating systems are supported by an api, look under the Requirements section of that api in MSDN.
    CreateFile

  6. #6
    Join Date
    Dec 2004
    Location
    Pakistan(Skardu)
    Posts
    64

    Re: write data on LPT Port using win32

    Actually i want to write bit on printer port pin.i has been done it in delphi,if we write 1 on a pin then it show high voltage and 0 for low,i just need a simple code that how i can write
    data in a printer port on any PIN,
    In simple C we use
    outportb(port NO,value); can it work for my this problem in vc++.

    I m using XP and Tool VC++ 6.0

  7. #7
    Join Date
    May 2005
    Posts
    4,954

    Re: write data on LPT Port using win32

    Quote Originally Posted by kku
    can it work for my this problem in vc++.
    Your question is not clear you have been told above how to do it, you can also look at this article: Using standard printing from windows

    please be more specific.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  8. #8
    Join Date
    Jan 2006
    Posts
    35

    Re: write data on LPT Port using win32

    I know CreateFile will work under NT,2000,XP but if you try to obtain a handle and access the port don't you generate an exception? It's been a while but as I recall you get a priviliged instruction exception. Not true?

  9. #9
    Join Date
    May 2005
    Posts
    4,954

    Re: write data on LPT Port using win32

    Quote Originally Posted by eeboy
    I know CreateFile will work under NT,2000,XP but if you try to obtain a handle and access the port don't you generate an exception? It's been a while but as I recall you get a priviliged instruction exception. Not true?


    First ::CreateFile(..) will work in win95 and higher you can refer to msdn for more info, look at leojose post.

    Now to your question about exception, why do you think you will get exception if you try open that port via ::CreateFile(..) ?

    Did you try it and get exception? You should check the handle you get and if its INVALID_HANDLE_VALUE you can use ::GetLastError() for more info about the failure.


    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured