Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use "createfile" function under win2000

Posted on 2001-08-09
9
Medium Priority
?
707 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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