Solved

How to use "createfile" function under win2000

Posted on 2001-08-09
9
691 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
Comment Utility
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
Comment Utility
I never install any printer driver and windows2000 cannot detect and install any printer driver also.
0
 
LVL 4

Expert Comment

by:fva
Comment Utility
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
 

Author Comment

by:zhiyuan-yang
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 11

Expert Comment

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

Expert Comment

by:Johnch
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now