Solved

How to use "createfile" function under win2000

Posted on 2001-08-09
9
692 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't connect to Outlook via TOutlookApplication component 15 121
delphi custom sort exception 6 137
proper way to parse url in delphi 2 165
delphi prevent click fast 2 191
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…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

867 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

24 Experts available now in Live!

Get 1:1 Help Now