Solved

How to use "createfile" function under win2000

Posted on 2001-08-09
9
693 Views
Last Modified: 2012-06-27
I want to open a LPT1 port and send code to it.
I use createfile function under win98 is ok but win2000 didn't pass.
like this:
var
 PrnHwnd:THandle;

{$R *.DFM}

procedure OpenLptPrn(hp:string);
begin
    PRNHwnd:=CreateFile(Pchar(hp),
                        GENERIC_READ or GENERIC_WRITE,
                        0,
                        nil,
                        OPEN_EXISTING,
                        FILE_FLAG_OVERLAPPED,
                        0);
if PRNHwnd=INVALID_HANDLE_VALUE then showmessage('false');
end;

procedure SendToPrinter(SendBuf:array of byte);overload
var
   tem:cardinal;
begin
     WriteFile(PRNHwnd,SendBuf,High(SendBuf)+1,tem,nil);
end;

0
Comment
Question by:zhiyuan-yang
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6371419
You should ask yourself why you are not allowed to open LPT1.
The answer is because the device is already under the exclusive control of a program. The printer driver.
Form the point of view of the OS the printer driver IS the printer. No other access should be allowed and in Windows 2000 no other access is allowed.
0
 

Author Comment

by:zhiyuan-yang
ID: 6371446
I never install any printer driver and windows2000 cannot detect and install any printer driver also.
0
 
LVL 4

Expert Comment

by:fva
ID: 6371647
Can you execute successfully the following in a cmd prompt?(with results from the printer, too)

copy <text_file_name_here> lpt1:


Maybe the account you are running under lacks some privileges.

F.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:zhiyuan-yang
ID: 6371738
I try it,no error come out.
no results from the pinter.

c:\>copy con test.txt
my data (ctrl+z)
c:\>copy test.txt lpt1:

right?
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6371826
Add a FormFeed char or the printer will buffer the page.
0
 
LVL 1

Expert Comment

by:Johnch
ID: 6371884
I have looked at this before, I was reading and writing data to the parallel port, under windows 95/98 its is possible, but Windows NT, 2000 protects it.

To get round the problem I had to download a service program, which gave access to the port to my application.

I'll try looking for the service program.


John.
0
 
LVL 1

Expert Comment

by:Johnch
ID: 6371916
Try looking at one of these components


http://uk.torry.net/portaccess.htm


one of them should help you.


John.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6371985
Do you get an invalid handle upon opening the port with CreateFile in Windows 2000? If yes, what's the content of GetLastError? And have you made sure that the port is properly working under 2000 in general (i.e. can OTHER applications access it correctly)?
0
 
LVL 3

Accepted Solution

by:
VSF earned 100 total points
ID: 6372074
Go to this site and download the ZLPortIO for Delphi... It will solve your problems about port access on Win2000!

ZLPortIO
http://www.specosoft.com
Description
This unit allow your application direct access port input and output under all versions of Microsoft Windows.

Hope this helps!

VSF
www.victory.hpg.com.br
UIN:14016999
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 69
Reconfigure Delphi Install? 2 51
Graphics32 under Delphi 10.1 Berlin 2 67
firemonkey Android Listview Sort items 7 15
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 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