Solved

How to use "createfile" function under win2000

Posted on 2001-08-09
9
694 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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