Witam mam identyczny problem z szybkością Timer'a, problem w tym ze nie wiem czy szybkość, jaką ja chce otrzymać, jest możliwa do osiągnięcia... potrzebowałbym t=500ns , ewentualnie 1us Lpt ma sterować odczytem danych (zadawanie CLK) dla (poszczególnych pixeli)z czujnika odciska palca. Do obsługi chciałem użyć komponentu dlPortIO ----------------------------------------------------------------------------------- komponent wskazany przez 'Bielsky' nie chce mi się przyjąć do Delphi 7 czy ktoś umie rozwiązać ten problem...... FTimerHandle :=timeSetEvent(FInterval, FResolution, TimeCallBack, LongInt(DSeg), TIME_PERIODIC); { ^^^^ send DSeg of this unit to callback-function} ============================================== RTCS.PAS(106): Incompatible types: 'Calling conventions differ' RTCS.PAS(107): Undeclared identifier: 'DSeg' dclusr.dpk(38): Could not compile used unit 'E:\test\RTCS.PAS' ----------------------------------------------------------------------------------- dla osób szukających komponentów do LPT dodaje pliki : dlPortIO instalka komponentu/ przykład dla Delphi i C++ opis działania komponentu PortIO zlPortIO
//---------------------------------------------------------------------------
#ifndef DLPrinterPortIOXControl_ATLH
#define DLPrinterPortIOXControl_ATLH
// Check if we're using ATLVCL
//
#if defined(USING_ATLVCL)
// To get declaration of _Module
//
#include & lt; atl\atlvcl.h & gt;
#elif defined(USING_ATL)
// Light-weight ATL support
//
#include & lt; utilcls.h & gt; // _ASSERTE
#include & lt; atlbase.h & gt;
// NOTE: You may derive a class from TComModule and use it as your server's
// module object. (i.e. Assign an instance of that class to _Module).
// However, you must *NOT* change the name _Module.
//
extern CComModule _Module;
#include & lt; atlcom.h & gt;
#include & lt; shellapi.h & gt;
#include & lt; atlctl.h & gt;
#endif
#endif // DLPrinterPortIOXControl1_ATLH
//*** TDLPortIO: DriverLINX Port IO Driver wrapper component *****************
//** **
//** File: Main.cpp **
//** **
//** Copyright (c) 1999 John Pappas (DiskDude). All rights reserved. **
//** This software is FreeWare. **
//** **
//** Please notify me if you make any changes to this file. **
//** Email: diskdude@poboxes.com **
//** **
//*** http://diskdude.cjb.net/ ***********************************************
#include & lt; vcl.h & gt;
#pragma hdrstop
#include " Main.h "
#pragma package(smart_init)
#pragma resource " *.dfm "
TMain_Win *Main_Win;
// WinNT DriverLINX Information
const AnsiString DRIVER_NAME = " DLPortIO " ;
const AnsiString DISPLAY_NAME = " DriverLINX Port I/O Driver " ;
const AnsiString DRIVER_GROUP = " SST miniport drivers " ;
//---------------------------------------------------------------------------
// TMain_Win()
//---------------------------------------------------------------------------
__fastcall TMain_Win::TMain_Win(TComponent* Owner) : TForm(Owner)
{
// Are we running Windows NT?
OSVERSIONINFO os;
memset( & os, NULL, sizeof(OSVERSIONINFO));
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx( & os);
FRunningWinNT=(os.dwPlatformId==VER_PLATFORM_WIN32_NT);
// Get the Windows NT driver path
char Buffer[MAX_PATH];
GetSystemDirectory(Buffer, MAX_PATH);
FDriverPath = AnsiString(Buffer)+ " \\DRIVERS " ;
// Get the Windows System path
FDLLPath = AnsiString(Buffer);
// Get the program path (path of .EXE)
FProgPath = ExtractFileDir(ParamStr(0));
if (FProgPath.c_str()[FProgPath.Length()-1]=='\\')
FProgPath=FProgPath.SubString(1, FProgPath.Length()-1);
}
//---------------------------------------------------------------------------
// InstallDriver()
// Installs the DriverLINX driver into the registry.
//---------------------------------------------------------------------------
bool __fastcall TMain_Win::InstallDriver()
{
DWORD dwStatus = 0; // Assume success, until we prove otherwise
SC_HANDLE hSCMan; // For use with WinNT Service Control Manager
SC_HANDLE hService; // Handle to the new service
// Driver path including filename
AnsiString DriverPath = FDriverPath+ " \\ " +DRIVER_NAME+ " .SYS " ;
// Connect to the SCM as Administrator
hSCMan = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCMan!=NULL)
{
// Is the DriverLINX driver already in the SCM? If so, indicate success.
hService=OpenService(hSCMan, DRIVER_NAME.c_str(), SERVICE_QUERY_STATUS);
if (hService!=NULL)
{
CloseServiceHandle(hService); // Close the service
CloseServiceHandle(hSCMan); // Disconnect from the SCM
return true; // Success
}
// Install the driver to the system
hService=CreateService(
hSCMan,
DRIVER_NAME.c_str(),
DISPLAY_NAME.c_str(),
SERVICE_ALL_ACCESS,
SERVICE_KERNEL_DRIVER,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
DriverPath.c_str(),
DRIVER_GROUP.c_str(),
NULL, NULL, NULL, NULL);
if (hService==NULL)
dwStatus=GetLastError();
else
CloseServiceHandle(hService);
// Disconnect from the SCM
CloseServiceHandle(hSCMan);
}
else
dwStatus=GetLastError();
return dwStatus==0; // Success == 0
}
//---------------------------------------------------------------------------
// CancelButtonClick()
// Quit the installer
//---------------------------------------------------------------------------
void __fastcall TMain_Win::CancelButtonClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
// InstallButtonClick()
// Install the drivers
//---------------------------------------------------------------------------
void __fastcall TMain_Win::InstallButtonClick(TObject *Sender)
{
bool ErrorOccurred = false; // Assume error free until we find an error
// Source paths for the files
AnsiString DLLPathSrc = FProgPath + " \\DLPortIO.DLL " ;
AnsiString DriverPathSrc = FProgPath + " \\DLPortIO.SYS " ;
// Destination paths for the files
AnsiString DLLPathDest = FDLLPath + " \\DLPortIO.DLL " ;
AnsiString DriverPathDest = FDriverPath + " \\DLPortIO.SYS " ;
// Disable buttons until we're done
InstallButton- & gt; Enabled=false;
CancelButton- & gt; Enabled=false;
// Hide the fist panel, and show the second
InstructionPanel- & gt; Visible=false;
InstallPanel- & gt; Visible=true;
// Copy the DriverLINX DLL
InstallText- & gt; Caption= " \nCopying 'dlportio.dll' into " +
FDLLPath.LowerCase()+ " ... " ;
InstallText- & gt; Refresh();
if (CopyFile(DLLPathSrc.c_str(), DLLPathDest.c_str(), false))
InstallText- & gt; Caption=InstallText- & gt; Caption+ " done\n " ;
else
{
InstallText- & gt; Caption=InstallText- & gt; Caption+ " error!\n " ;
ErrorOccurred=true;
}
if (!ErrorOccurred & & FRunningWinNT)
{
// Copy the DriverLINX kernel mode driver
InstallText- & gt; Caption=InstallText- & gt; Caption+ " Copying 'dlportio.sys' into " +
FDriverPath.LowerCase()+ " ... " ;
InstallText- & gt; Refresh();
CreateDirectory(FDriverPath.c_str(), NULL);
if (CopyFile(DriverPathSrc.c_str(), DriverPathDest.c_str(), false))
InstallText- & gt; Caption=InstallText- & gt; Caption+ " done\n " ;
else
{
InstallText- & gt; Caption=InstallText- & gt; Caption+ " error!\n " ;
ErrorOccurred=true;
}
// Install the DriverLINX kernel mode driver into the system, if
// no errors have occurred so far.
if (!ErrorOccurred)
{
InstallText- & gt; Caption=InstallText- & gt; Caption+ " Installing Windows NT driver... " ;
InstallText- & gt; Refresh();
if (InstallDriver())
InstallText- & gt; Caption=InstallText- & gt; Caption+ " done\n " ;
else
{
ErrorOccurred=true;
InstallText- & gt; Caption=InstallText- & gt; Caption+ " error!\n " ;
}
}
}
// Display a conclusion
if (ErrorOccurred)
// An installation error occurred
InstallText- & gt; Caption=InstallText- & gt; Caption+
" \n\nAn error occurred; please make sure that the "
" relavent files (DLPortIO.DLL and DLPortIO.SYS) "
" are located in the same directory as this "
" program, and you are running this program under "
" an administrator account if using Windows NT. " ;
else
// Installation success: need to reboot the PC
InstallText- & gt; Caption=InstallText- & gt; Caption+
" \n\nInstallation complete.\n " +
" \nYou need to reboot for the driver to take "
" effect. " ;
// Re-enable buttons
CancelButton- & gt; Caption= " & Exit " ;
CancelButton- & gt; Enabled=true;
CancelButton- & gt; SetFocus();
}
//*** TDLPortIO: DriverLINX Port IO Driver wrapper component *****************
//** **
//** File: Main.h **
//** **
//** Copyright (c) 1999 John Pappas (DiskDude). All rights reserved. **
//** This software is FreeWare. **
//** **
//** Please notify me if you make any changes to this file. **
//** Email: diskdude@poboxes.com **
//** **
//*** http://diskdude.cjb.net/ ***********************************************
#ifndef __Main_H__
#define __Main_H__
#include & lt; Classes.hpp & gt;
#include & lt; Controls.hpp & gt;
#include & lt; StdCtrls.hpp & gt;
#include & lt; Forms.hpp & gt;
#include & lt; ExtCtrls.hpp & gt;
//---------------------------------------------------------------------------
// TMain_Win class
//---------------------------------------------------------------------------
class TMain_Win : public TForm
{
__published: // IDE-managed Components
TImage *InstallImage;
TBevel *Bevel1;
TButton *CancelButton;
TButton *InstallButton;
TPanel *InstructionPanel;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TPanel *InstallPanel;
TLabel *InstallText;
void __fastcall CancelButtonClick(TObject *Sender);
void __fastcall InstallButtonClick(TObject *Sender);
private: // User declarations
bool FRunningWinNT; // True when we're running Windows NT
AnsiString FDLLPath; // Windows System directory
AnsiString FDriverPath; // Windows System\Drivers directory
AnsiString FProgPath; // Directory of this program
// Installs the DriverLINX driver into the registry
bool __fastcall InstallDriver();
public: // User declarations
__fastcall TMain_Win(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TMain_Win *Main_Win;
//---------------------------------------------------------------------------
#endif
DriverLINX Port I/O Driver for Win95 and WinNT
(C) Copyright 1996, Scientific Software Tools, Inc.
All Rights Reserved.
Scientific Software Tools, Inc. is pleased to provide you with this utility
for performing hardware port I/O under Windows 95 and Windows NT. This
product allows your 32-bit C/C++ or Visual Basic apps (or any language that
can call a DLL) direct access to the I/O ports over the range 0100H to FFFFH.
This product contains the following components:
DLPortIO.DLL -- Win32 DLL hardware I/O functions
DLPortIO.H -- C/C++ interface to DLPortIO.DLL
DLPortIO.BAS -- Visual Basic interface to DLPortIO.DLL
DLPortIO.SYS -- Kernel mode driver for WinNT (not required for Win95)
MSVC example
VB example
If you're unsure how to interface your app to DLPortIO.DLL, please look at
the source code files for simple examples.
You are free to copy and distribute this product as long as this package is
distributed in its entirety and SST's copyright and trademark notices are not
removed. Please see the license file for more information.
This product is provided without charge so we can't provide any technical
support for it. However, if you find any problems, please e-mail us at
support@sstnet.com with a complete description of the problem.
About Scientific Software Tools, Inc.
-------------------------------------
Scientific Software Tools, Inc. (SST) develops and markets award-winning,
commercial Windows products for the test/measurement and industrial
marketplace and provides product development services for other companies.
SST's product development expertise spans from systems-level components,
e.g., OCX/ActiveX, VxD, and NT kernel drivers to full commercial
applications.
For more information, please contact us at
Scientific Software Tools, Inc.
19 E. Central Avenue
Paoli, PA 19301
(610) 889-1354
(610) 889-1556 Fax
E-mail: sales@sstnet.com
Web: www.sstnet.com
-----
DriverLINX is a registered trademark of Scientific Software Tools, Inc.
Microsoft, Windows, Win95, WinNT, and Visual Basic are registered trademarks
of Microsoft Corporation.
DriverLINX Port I/O Driver for Win95 and WinNT
(C) Copyright 1996, Scientific Software Tools, Inc.
All Rights Reserved.
You are free to copy and distribute this product as long as this package is
distributed in its entirety and Scientific Software Tools' copyright and
trademark notices are not removed.
The software and accompanying written materials (including instructions for
use) are provided " as is " without warranty of any kind. Further, Scientific
Software Tools, Inc. does not warrant, guarantee, or make any representations
regarding the use, or the results of the use, of the software or written
materials in terms of correctness, accuracy, reliability, currentness, or
otherwise. The entire risk as to the results and performance of the software
is assumed by Licensee and not by Scientific Software Tools, Inc. or its
distributors, agents or employees.
THERE ARE NO OTHER WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE, THE
ACCOMPANYING WRITTEN MATERIALS, AND ANY ACCOMPANYING HARDWARE.
Scientific Software Tools, Inc.
19 E. Central Avenue
Paoli, PA 19301
Phone: (610) 889-1354
Fax: (610) 889-1556
E-mail: sales@sstnet.com
Web: www.sstnet.com
-----
DriverLINX is a registered trademark of Scientific Software Tools, Inc.
Microsoft, Windows, Win95, and WinNT are registered trademarks of Microsoft
Corporation.
/****************************************************************************
* @doc INTERNAL
* @module dlportio.h |
*
* DriverLINX Port I/O Driver Interface
* & lt; cp & gt; Copyright 1996 Scientific Software Tools, Inc. & lt; nl & gt;
* All Rights Reserved. & lt; nl & gt;
* DriverLINX is a registered trademark of Scientific Software Tools, Inc.
*
* Win32 Prototypes for DriverLINX Port I/O
*
* Please report bugs to:
* Scientific Software Tools, Inc.
* 19 East Central Avenue
* Paoli, PA 19301
* USA
* E-mail: support@sstnet.com
* Web: www.sstnet.com
*
* @comm
* Author: RoyF & lt; nl & gt;
* Date: 09/26/96 14:08:58
*
* @group Revision History
* @comm
* $Revision: 1 $
* & lt; nl & gt;
* $Log: /DLPortIO/API/DLPORTIO.H $
*
* 1 9/27/96 2:03p Royf
* Initial revision.
*
****************************************************************************/
#ifndef DLPORTIO_H
#define DLPORTIO_H
#ifdef __cplusplus
extern " C " {
#endif
#ifndef IN
#define IN
#endif
#define DLPORT_API _stdcall
UCHAR DLPORT_API
DlPortReadPortUchar(
IN ULONG Port
);
USHORT DLPORT_API
DlPortReadPortUshort(
IN ULONG Port
);
ULONG DLPORT_API
DlPortReadPortUlong(
IN ULONG Port
);
VOID DLPORT_API
DlPortReadPortBufferUchar(
IN ULONG Port,
IN PUCHAR Buffer,
IN ULONG Count
);
VOID DLPORT_API
DlPortReadPortBufferUshort(
IN ULONG Port,
IN PUSHORT Buffer,
IN ULONG Count
);
VOID DLPORT_API
DlPortReadPortBufferUlong(
IN ULONG Port,
IN PULONG Buffer,
IN ULONG Count
);
VOID DLPORT_API
DlPortWritePortUchar(
IN ULONG Port,
IN UCHAR Value
);
VOID DLPORT_API
DlPortWritePortUshort(
IN ULONG Port,
IN USHORT Value
);
VOID DLPORT_API
DlPortWritePortUlong(
IN ULONG Port,
IN ULONG Value
);
VOID DLPORT_API
DlPortWritePortBufferUchar(
IN ULONG Port,
IN PUCHAR Buffer,
IN ULONG Count
);
VOID DLPORT_API
DlPortWritePortBufferUshort(
IN ULONG Port,
IN PUSHORT Buffer,
IN ULONG Count
);
VOID DLPORT_API
DlPortWritePortBufferUlong(
IN ULONG Port,
IN PULONG Buffer,
IN ULONG Count
);
#ifdef __cplusplus
}
#endif
#endif // DLPORTIO_H
//*** TDLPortIO: DriverLINX Port IO Driver wrapper component *****************
//** **
//** File: TDLPortIO.cpp **
//** **
//** Copyright (c) 1999 John Pappas (DiskDude). All rights reserved. **
//** This software is FreeWare. **
//** **
//** Please notify me if you make any changes to this file. **
//** Email: diskdude@poboxes.com **
//** **
//** **
//** The following resources helped in developing the install, start, stop **
//** and remove code for dynamically opening/closing the DriverLINX WinNT **
//** kernel mode driver. **
//** **
//** " Dynamically Loading Drivers in Windows NT " by Paula Tomlinson **
//** from " Windows Developer's Journal " , Volume 6, Issue 5. (C code) **
//** ftp://ftp.mfi.com/pub/windev/1995/may95.zip **
//** **
//** " Hardware I/O Port Programming with Delphi and NT " by Graham Wideman **
//** http://www.wideman-one.com/tech/Delphi/IOPM/index.htm **
//** **
//** **
//** Special thanks to Peter Holm & lt; comtext3@post4.tele.dk & gt; for his **
//** algorithm and code for detecting the number and addresses of the **
//** installed printer ports, on which the detection code below is based. **
//** **
//*** http://diskdude.cjb.net/ ***********************************************
#include & lt; vcl.h & gt;
#include & lt; stdlib.h & gt;
#include & lt; string.h & gt;
#pragma hdrstop
#include " TDLPortIOX.h "
//---------------------------------------------------------------------------
// Constants
//---------------------------------------------------------------------------
// DriverLINX DLL filename
const AnsiString LIBRARY_FILENAME = " DLPortIO.dll " ;
// WinNT DriverLINX Information
const AnsiString DRIVER_NAME = " DLPortIO " ;
const AnsiString DISPLAY_NAME = " DriverLINX Port I/O Driver " ;
const AnsiString DRIVER_GROUP = " SST miniport drivers " ;
// Define to do a little less error checking
#define FAST
//*************************************************************************//
// TDLPortIO class implementation
//*************************************************************************//
//---------------------------------------------------------------------------
// TDLPortIO()
//---------------------------------------------------------------------------
__fastcall TDLPortIOX::TDLPortIOX(TComponent *Owner) : TCustomControl(Owner)
{
// Are we running Windows NT?
OSVERSIONINFO os;
memset( & os, NULL, sizeof(OSVERSIONINFO));
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx( & os);
FRunningWinNT=(os.dwPlatformId==VER_PLATFORM_WIN32_NT);
// Set default WinNT driver path
char Buffer[MAX_PATH];
GetSystemDirectory(Buffer, MAX_PATH);
FDriverPath = AnsiString(Buffer)+ " \\DRIVERS " ;
// Set the default DLL path
FDLLPath= " " ;
FActiveHW=false; // DLL/Driver not loaded
FHardAccess=true; // Not used, default true
FLastError= " " ; // No errors yet
}
//---------------------------------------------------------------------------
// ~TDLPortIO()
//---------------------------------------------------------------------------
__fastcall TDLPortIOX::~TDLPortIOX()
{
// Make sure we close the DLL
if (IsLoaded()) CloseDriver();
}
//---------------------------------------------------------------------------
// Paint()
// Paints our little icon
//---------------------------------------------------------------------------
void __fastcall TDLPortIOX::Paint()
{
// The icon, as a BMP :-)
const BYTE Icon[] = {0x42, 0x4D, 0x22, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00,
0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x02, 0x00,
0x00, 0x00, 0xAC, 0x01, 0x00, 0x00, 0xC3, 0x0E,
0x00, 0x00, 0xC3, 0x0E, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x80, 0x80,
0x80, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x1C, 0x88,
0x00, 0x00, 0x00, 0x06, 0xF8, 0x70, 0x07, 0x00,
0x14, 0x77, 0x02, 0x78, 0x00, 0x00, 0x00, 0x06,
0xF8, 0x70, 0x07, 0x00, 0x14, 0x77, 0x02, 0x78,
0x00, 0x00, 0x00, 0x06, 0xF8, 0x70, 0x00, 0x00,
0x14, 0x77, 0x02, 0x78, 0x00, 0x00, 0x00, 0x04,
0xF8, 0x78, 0x0C, 0x00, 0x02, 0x07, 0x08, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x06, 0xF8, 0x87,
0x80, 0x00, 0x0C, 0x00, 0x08, 0x77, 0x02, 0x78,
0x00, 0x00, 0x02, 0xF0, 0x0A, 0x88, 0x00, 0x10,
0x87, 0x77, 0x00, 0x07, 0x77, 0x77, 0x77, 0x78,
0x00, 0x00, 0x00, 0x06, 0xF7, 0x00, 0x08, 0x00,
0x08, 0x88, 0x00, 0x0E, 0x87, 0x70, 0x07, 0x77,
0x77, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x0C, 0x77, 0x00, 0x0E, 0x78, 0x80, 0x07, 0x77,
0x77, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x0C, 0x77, 0x00, 0x0E, 0x78, 0x80, 0x07, 0x77,
0x77, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x0C, 0x77, 0x00, 0x0E, 0x78, 0x88, 0x00, 0x77,
0x77, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x0C, 0x77, 0x00, 0x0E, 0x78, 0x88, 0x80, 0x07,
0x77, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x0C, 0x77, 0x00, 0x0E, 0x70, 0x00, 0x00, 0x07,
0x77, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x0C, 0x77, 0x08, 0x00, 0x00, 0x06, 0x77, 0x77,
0x78, 0x00, 0x00, 0x00, 0x02, 0xF7, 0x0A, 0x77,
0x00, 0x10, 0x70, 0xFF, 0x88, 0x88, 0x80, 0x77,
0x77, 0x78, 0x00, 0x00, 0x02, 0xF7, 0x0A, 0x77,
0x00, 0x10, 0x70, 0xFF, 0x77, 0x77, 0x70, 0x07,
0x77, 0x78, 0x00, 0x00, 0x02, 0xF7, 0x08, 0x77,
0x00, 0x04, 0x78, 0xFF, 0x08, 0x77, 0x00, 0x06,
0x80, 0x77, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x08, 0x77, 0x00, 0x04, 0x78, 0xFF, 0x08, 0x77,
0x00, 0x06, 0x80, 0x07, 0x78, 0x00, 0x00, 0x00,
0x02, 0xF7, 0x08, 0x77, 0x00, 0x04, 0x78, 0xFF,
0x08, 0x77, 0x00, 0x06, 0x80, 0x07, 0x78, 0x00,
0x00, 0x00, 0x02, 0xF7, 0x08, 0x77, 0x00, 0x04,
0x78, 0xFF, 0x08, 0x77, 0x00, 0x06, 0x80, 0x07,
0x78, 0x00, 0x00, 0x00, 0x02, 0xF7, 0x08, 0x77,
0x00, 0x04, 0x78, 0xFF, 0x08, 0x77, 0x00, 0x06,
0x80, 0x07, 0x78, 0x00, 0x00, 0x00, 0x02, 0xF7,
0x08, 0x77, 0x00, 0x04, 0x78, 0xFF, 0x08, 0x77,
0x00, 0x06, 0x80, 0x07, 0x78, 0x00, 0x00, 0x00,
0x00, 0x0C, 0xF7, 0x77, 0x77, 0x77, 0x78, 0xFF,
0x0A, 0x77, 0x00, 0x06, 0x78, 0x80, 0x78, 0x00,
0x00, 0x00, 0x00, 0x0C, 0xF7, 0x77, 0x77, 0x77,
0x78, 0xFF, 0x0A, 0x77, 0x00, 0x06, 0x78, 0x80,
0x08, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xF7, 0x77,
0x77, 0x77, 0x78, 0x00, 0x0E, 0xFF, 0x00, 0x04,
0xF0, 0x08, 0x00, 0x00, 0x00, 0x0A, 0xF7, 0x77,
0x77, 0x77, 0x78, 0x00, 0x0E, 0xFF, 0x00, 0x04,
0xF0, 0x08, 0x00, 0x00, 0x02, 0xF7, 0x08, 0x77,
0x00, 0x12, 0x7B, 0xB3, 0x3B, 0xB3, 0x3B, 0xB8,
0x8B, 0xB7, 0x78, 0x00, 0x00, 0x00, 0x1C, 0xFF,
0x00, 0x01};
TMemoryStream *Buffer;
Graphics::TBitmap *Bitmap;
Buffer = new TMemoryStream();
if (Buffer==NULL) return;
Bitmap = new Graphics::TBitmap();
if (Bitmap==NULL)
{
delete Buffer;
return;
}
Buffer- & gt; Write(Icon, 546);
Buffer- & gt; Seek(0, soFromBeginning);
Bitmap- & gt; LoadFromStream(Buffer);
Canvas- & gt; Draw(0, 0, Bitmap);
delete Bitmap;
delete Buffer;
}
//---------------------------------------------------------------------------
// ConnectSCM()
// Connects to the WinNT Service Control Manager
//---------------------------------------------------------------------------
bool TDLPortIOX::ConnectSCM()
{
DWORD dwStatus = 0; // Assume success, until we prove otherwise
DWORD scAccess; // Access mode when connecting to SCM
// Try and connect as administrator
scAccess = SC_MANAGER_CONNECT |
SC_MANAGER_QUERY_LOCK_STATUS |
SC_MANAGER_ENUMERATE_SERVICE |
SC_MANAGER_CREATE_SERVICE; // Admin only
// Connect to the SCM
hSCMan = OpenSCManager(NULL, NULL, scAccess);
// If we're not in administrator mode, try and reconnect
if (hSCMan==NULL & & GetLastError()==ERROR_ACCESS_DENIED)
{
scAccess = SC_MANAGER_CONNECT |
SC_MANAGER_QUERY_LOCK_STATUS |
SC_MANAGER_ENUMERATE_SERVICE;
// Connect to the SCM
hSCMan = OpenSCManager(NULL, NULL, scAccess);
}
// Did it succeed?
if (hSCMan==NULL)
{
// Failed, save error information
dwStatus=GetLastError();
FLastError= " ConnectSCM: Error # " +IntToStr(dwStatus);
}
return dwStatus==0; // Success == 0
}
//---------------------------------------------------------------------------
// DisconnectSCM()
// Disconnects from the WinNT Service Control Manager
//---------------------------------------------------------------------------
void TDLPortIOX::DisconnectSCM()
{
if (hSCMan != NULL)
{
// Disconnect from our local Service Control Manager
CloseServiceHandle(hSCMan);
hSCMan=NULL;
}
}
//---------------------------------------------------------------------------
// DriverInstall()
// Installs the DriverLINX driver into Windows NT's registry
//---------------------------------------------------------------------------
bool TDLPortIOX::DriverInstall()
{
SC_HANDLE hService; // Handle to the new service
DWORD dwStatus = 0; // Assume success, until we prove otherwise
FDrvPrevInst=false; // Assume the driver wasn't installed previously
// Path including filename
AnsiString DriverPath = FDriverPath+ " \\ " +DRIVER_NAME+ " .SYS " ;
// Is the DriverLINX driver already in the SCM? If so,
// indicate success and set FDrvPrevInst to true.
hService=OpenService(hSCMan, DRIVER_NAME.c_str(), SERVICE_QUERY_STATUS);
if (hService!=NULL)
{
FDrvPrevInst=true; // Driver previously installed, don't remove
CloseServiceHandle(hService); // Close the service
return true; // Success
}
// Add to our Service Control Manager's database
hService=CreateService(
hSCMan,
DRIVER_NAME.c_str(),
DISPLAY_NAME.c_str(),
SERVICE_START | SERVICE_STOP | DELETE | SERVICE_QUERY_STATUS,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
DriverPath.c_str(),
DRIVER_GROUP.c_str(),
NULL, NULL, NULL, NULL);
if (hService==NULL)
dwStatus=GetLastError();
else
// Close the service for now...
CloseServiceHandle(hService);
if (dwStatus!=0)
FLastError= " DriverInstall: Error # " +IntToStr(dwStatus);
return dwStatus==0; // Success == 0
}
//---------------------------------------------------------------------------
// DriverStart()
// Starts the Windows NT DriverLINX driver for use
//---------------------------------------------------------------------------
bool TDLPortIOX::DriverStart()
{
SC_HANDLE hService; // Handle to the service to start
DWORD dwStatus = 0; // Assume success, until we prove otherwise
SERVICE_STATUS sStatus;
FDrvPrevStart=false; // Assume the driver was not already running
hService = OpenService(hSCMan, DRIVER_NAME.c_str(), SERVICE_QUERY_STATUS);
if (hService!=NULL & & QueryServiceStatus(hService, & sStatus))
{
// Got the service status, now check it
if (sStatus.dwCurrentState==SERVICE_RUNNING)
{
FDrvPrevStart=true; // Driver was previously started
CloseServiceHandle(hService); // Close service
return true; // Success
}
else if (sStatus.dwCurrentState==SERVICE_STOPPED)
{
// Driver was stopped. Start the driver.
CloseServiceHandle(hService);
hService = OpenService(hSCMan, DRIVER_NAME.c_str(), SERVICE_START);
if (!StartService(hService, 0, NULL))
dwStatus=GetLastError();
CloseServiceHandle(hService); // Close service
}
else dwStatus=-1; // Can't run the service
}
else
dwStatus=GetLastError();
if (dwStatus!=0)
FLastError= " DriverStart: Error # " +IntToStr(dwStatus);
return dwStatus==0; // Success == 0
}
//---------------------------------------------------------------------------
// DriverStop()
// Stops a Windows NT driver from use
//---------------------------------------------------------------------------
bool TDLPortIOX::DriverStop()
{
SC_HANDLE hService; // Handle to the service to start
DWORD dwStatus = 0; // Assume success, until we prove otherwise
// If we didn't start the driver, then don't stop it.
// Pretend we stopped it, by indicating success.
if (FDrvPrevStart) return true;
// Get a handle to the service to stop
hService = OpenService(
hSCMan,
DRIVER_NAME.c_str(),
SERVICE_STOP | SERVICE_QUERY_STATUS);
if (hService!=NULL)
{
// Stop the driver, then close the service
SERVICE_STATUS sStatus;
if (!ControlService(hService, SERVICE_CONTROL_STOP, & sStatus))
dwStatus = GetLastError();
// Close the service
CloseServiceHandle(hService);
}
else
dwStatus = GetLastError();
if (dwStatus!=0)
FLastError= " DriverStop: Error # " +IntToStr(dwStatus);
return dwStatus==0; // Success == 0
}
//---------------------------------------------------------------------------
// DriverRemove()
// Removes a driver from the Windows NT system (service manager)
//---------------------------------------------------------------------------
bool TDLPortIOX::DriverRemove()
{
SC_HANDLE hService; // Handle to the service to start
DWORD dwStatus = 0; // Assume success, until we prove otherwise
// If we didn't install the driver, then don't remove it.
// Pretend we removed it, by indicating success.
if (FDrvPrevInst) return true;
// Get a handle to the service to remove
hService = OpenService(
hSCMan,
DRIVER_NAME.c_str(),
DELETE);
if (hService!=NULL)
{
// Remove the driver then close the service again
if (!DeleteService(hService))
dwStatus = GetLastError();
// Close the service
CloseServiceHandle(hService);
}
else
dwStatus = GetLastError();
if (dwStatus!=0)
FLastError= " DriverRemove: Error # " +IntToStr(dwStatus);
return dwStatus==0; // Success == 0
}
//---------------------------------------------------------------------------
// OpenDriver()
// Opens the DLL dynamically
//---------------------------------------------------------------------------
void __fastcall TDLPortIOX::OpenDriver()
{
// If the DLL/driver is already open, then forget it!
if (IsLoaded()) return;
// If we're running Windows NT, install the driver then start it
if (FRunningWinNT)
{
// Connect to the Service Control Manager
if (!ConnectSCM()) return;
// Install the driver
if (!DriverInstall())
{
// Driver install failed, so disconnect from the SCM
DisconnectSCM();
return;
}
// Start the driver
if (!DriverStart())
{
// Driver start failed, so remove it then disconnect from SCM
DriverRemove();
DisconnectSCM();
return;
}
}
// Load DLL library
AnsiString LibraryFileName = LIBRARY_FILENAME;
if (FDLLPath.Length() & gt; 0)
LibraryFileName = FDLLPath+ " \\ " +LIBRARY_FILENAME;
FDLLInst=LoadLibrary(LibraryFileName.c_str());
if (FDLLInst!=NULL)
{
DlReadByte=(TDlPortReadPortUchar)
GetProcAddress(FDLLInst, " DlPortReadPortUchar " );
DlReadWord=(TDlPortReadPortUshort)
GetProcAddress(FDLLInst, " DlPortReadPortUshort " );
DlReadDWord=(TDlPortReadPortUlong)
GetProcAddress(FDLLInst, " DlPortReadPortUlong " );
DlWriteByte=(TDlPortWritePortUchar)
GetProcAddress(FDLLInst, " DlPortWritePortUchar " );
DlWriteWord=(TDlPortWritePortUshort)
GetProcAddress(FDLLInst, " DlPortWritePortUshort " );
DlWriteDWord=(TDlPortWritePortUlong)
GetProcAddress(FDLLInst, " DlPortWritePortUlong " );
DlReadBufferByte=(TDlPortReadPortBufferUchar)
GetProcAddress(FDLLInst, " DlPortReadPortBufferUchar " );
DlReadBufferWord=(TDlPortReadPortBufferUshort)
GetProcAddress(FDLLInst, " DlPortReadPortBufferUshort " );
DlReadBufferDWord=(TDlPortReadPortBufferUlong)
GetProcAddress(FDLLInst, " DlPortReadPortBufferUlong " );
DlWriteBufferByte=(TDlPortWritePortBufferUchar)
GetProcAddress(FDLLInst, " DlPortWritePortBufferUchar " );
DlWriteBufferWord=(TDlPortWritePortBufferUshort)
GetProcAddress(FDLLInst, " DlPortWritePortBufferUshort " );
DlWriteBufferDWord=(TDlPortWritePortBufferUlong)
GetProcAddress(FDLLInst, " DlPortWritePortBufferUlong " );
// Make sure all our functions are there
if (DlReadByte!=NULL & & DlReadWord!=NULL & & DlReadDWord!=NULL & &
DlWriteByte!=NULL & & DlWriteWord!=NULL & & DlWriteDWord!=NULL & &
DlReadBufferByte!=NULL & & DlReadBufferWord!=NULL & &
DlReadBufferDWord!=NULL & & DlWriteBufferByte!=NULL & &
DlWriteBufferWord!=NULL & & DlWriteBufferDWord!=NULL)
FActiveHW=true; // Success
}
// Did we fail?
if (!FActiveHW)
{
// If we're running Windows NT, stop the driver then remove it
// Forget about any return (error) values we might get...
if (FRunningWinNT)
{
DriverStop();
DriverRemove();
DisconnectSCM();
}
// Free the library
if (FDLLInst!=NULL)
{
FreeLibrary(FDLLInst);
FDLLInst=NULL;
}
}
}
//---------------------------------------------------------------------------
// CloseDriver()
// Closes the dynamically opened DLL
//---------------------------------------------------------------------------
void __fastcall TDLPortIOX::CloseDriver()
{
// Don't close anything if it wasn't opened previously
if (!IsLoaded()) return;
// If we're running Windows NT, stop the driver then remove it
if (FRunningWinNT)
{
if (!DriverStop()) return;
if (!DriverRemove()) return;
DisconnectSCM();
}
// Free the library
if (FreeLibrary(FDLLInst)==0) return;
FDLLInst=NULL;
FActiveHW=false; // Success
}
//*************************************************************************//
// TDLPrinterPortIO class implementation
//*************************************************************************//
//---------------------------------------------------------------------------
// TDLPrinterPortIO()
//---------------------------------------------------------------------------
__fastcall TDLPrinterPortIOX::TDLPrinterPortIOX(TComponent *Owner)
: TDLPortIOX(Owner),
FLPTNumber(0), // No LPT selected
FLPTBase(0), // No base address
FLPTCount(0) // No printer ports counted
{
// Detect the printer ports available
DetectPorts();
// Set the default LPT number
SetLPTNumber(1);
}
//---------------------------------------------------------------------------
// Paint()
// Paints our little icon
//---------------------------------------------------------------------------
void __fastcall TDLPrinterPortIOX::Paint()
{
// The icon, as a BMP :-)
const BYTE Icon[] = {0x42, 0x4D, 0xF6, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00,
0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x02, 0x00,
0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xC3, 0x0E,
0x00, 0x00, 0xC3, 0x0E, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x80, 0x80,
0x80, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x1C, 0x88,
0x00, 0x00, 0x02, 0xF7, 0x18, 0x77, 0x02, 0x78,
0x00, 0x00, 0x00, 0x04, 0xF7, 0x87, 0x16, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x04, 0xF7, 0x87,
0x16, 0x77, 0x02, 0x78, 0x00, 0x00, 0x00, 0x0A,
0xF7, 0x87, 0x00, 0x00, 0x00, 0x00, 0x10, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x0C, 0xF7, 0x00,
0x88, 0x88, 0x87, 0x07, 0x0E, 0x77, 0x02, 0x78,
0x00, 0x00, 0x00, 0x0C, 0xF7, 0x77, 0x77, 0x77,
0x78, 0x87, 0x0E, 0x77, 0x02, 0x78, 0x00, 0x00,
0x00, 0x0C, 0xF7, 0x77, 0x77, 0x77, 0x78, 0x80,
0x0E, 0x77, 0x02, 0x78, 0x00, 0x00, 0x00, 0x0C,
0xF7, 0x77, 0x77, 0x77, 0x70, 0x00, 0x0E, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x0E, 0xF7, 0x77,
0x77, 0x77, 0x0F, 0x88, 0x07, 0x00, 0x0C, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x0E, 0xF7, 0x77,
0x77, 0x78, 0xF7, 0x77, 0x80, 0x00, 0x0C, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x0E, 0xF7, 0x77,
0x77, 0x78, 0xF7, 0x77, 0x80, 0x00, 0x0C, 0x77,
0x02, 0x78, 0x00, 0x00, 0x00, 0x0E, 0xF7, 0x77,
0x77, 0x78, 0xF7, 0x77, 0x80, 0x00, 0x0A, 0x00,
0x00, 0x04, 0x77, 0x78, 0x00, 0x00, 0x00, 0x1C,
0xF7, 0x77, 0x77, 0x8F, 0x77, 0x77, 0x78, 0x07,
0x77, 0x77, 0x77, 0x07, 0x07, 0x78, 0x00, 0x00,
0x00, 0x0E, 0xF7, 0x77, 0x77, 0x8F, 0xFF, 0xFF,
0xFF, 0x00, 0x0A, 0x00, 0x00, 0x04, 0x70, 0x78,
0x00, 0x00, 0x00, 0x1C, 0xF7, 0x77, 0x77, 0x7B,
0x3B, 0x33, 0xB3, 0x77, 0x77, 0xBB, 0xB7, 0x70,
0x00, 0x78, 0x00, 0x00, 0x02, 0xF7, 0x08, 0x77,
0x02, 0x70, 0x08, 0x77, 0x00, 0x08, 0x17, 0x70,
0x70, 0x78, 0x00, 0x00, 0x02, 0xF7, 0x08, 0x77,
0x02, 0x70, 0x0C, 0x00, 0x00, 0x04, 0x77, 0x08,
0x00, 0x00, 0x02, 0xF7, 0x08, 0x77, 0x02, 0x70,
0x0A, 0x77, 0x00, 0x06, 0x07, 0x07, 0x08, 0x00,
0x00, 0x00, 0x02, 0xF7, 0x0A, 0x77, 0x0A, 0x00,
0x00, 0x06, 0x70, 0x70, 0x08, 0x00, 0x00, 0x00,
0x02, 0xF7, 0x0A, 0x77, 0x02, 0x70, 0x08, 0xFF,
0x00, 0x06, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00,
0x02, 0xF7, 0x0C, 0x77, 0x00, 0x0E, 0x0F, 0x00,
0x00, 0x0F, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
0x02, 0xF7, 0x0C, 0x77, 0x00, 0x0E, 0x0F, 0xFF,
0xFF, 0xFF, 0xF0, 0x77, 0x78, 0x00, 0x00, 0x00,
0x02, 0xF7, 0x0C, 0x77, 0x00, 0x0E, 0x70, 0xF0,
0x00, 0x00, 0xF0, 0x77, 0x78, 0x00, 0x00, 0x00,
0x02, 0xF7, 0x0C, 0x77, 0x02, 0x70, 0x08, 0xFF,
0x00, 0x04, 0x07, 0x78, 0x00, 0x00, 0x02, 0xF7,
0x0E, 0x77, 0x08, 0x00, 0x00, 0x04, 0x07, 0x78,
0x00, 0x00, 0x02, 0xF7, 0x18, 0x77, 0x02, 0x78,
0x00, 0x00, 0x1C, 0xFF, 0x00, 0x01};
TMemoryStream *Buffer;
Graphics::TBitmap *Bitmap;
Buffer = new TMemoryStream();
if (Buffer==NULL) return;
Bitmap = new Graphics::TBitmap();
if (Bitmap==NULL)
{
delete Buffer;
return;
}
Buffer- & gt; Write(Icon, 502);
Buffer- & gt; Seek(0, soFromBeginning);
Bitmap- & gt; LoadFromStream(Buffer);
Canvas- & gt; Draw(0, 0, Bitmap);
delete Bitmap;
delete Buffer;
}
//---------------------------------------------------------------------------
// DetectPorts()
//---------------------------------------------------------------------------
void __fastcall TDLPrinterPortIOX::DetectPorts()
{
bool RunningWinNT;
// Are we running Windows NT?
OSVERSIONINFO os;
memset( & os, NULL, sizeof(OSVERSIONINFO));
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx( & os);
RunningWinNT=(os.dwPlatformId==VER_PLATFORM_WIN32_NT);
// Detect the printer ports available
if (RunningWinNT)
DetectPortsNT(); // WinNT version
else
DetectPorts9x(); // Win9x version
}
//---------------------------------------------------------------------------
// DetectPorts9x()
//---------------------------------------------------------------------------
void __fastcall TDLPrinterPortIOX::DetectPorts9x()
{
const char *BASE_KEY = " Config Manager\\Enum " ;
const char *PROBLEM = " Problem " ;
const char *ALLOCATION = " Allocation " ;
const char *PORTNAME = " PortName " ;
const char *HARDWARE_KEY = " HardwareKey " ;
const REGSAM KEY_PERMISSIONS = KEY_ENUMERATE_SUB_KEYS |
KEY_QUERY_VALUE;
HKEY CurKey; // Current key when using the registry
char KeyName[MAX_PATH]; // A key name when using the registry
char **KeyList; // List of keys
DWORD KeyCount; // Count of the number of keys in KeyList
// Clear the port count
FLPTCount = 0;
// Clear the port array
for (int index=0; index & lt; =MAX_LPT_PORTS; index++)
FLPTAddress[index] = 0;
// Open the registry
RegOpenKeyEx(HKEY_DYN_DATA, BASE_KEY, 0, KEY_PERMISSIONS, & CurKey);
// Grab all the key names under HKEY_DYN_DATA
//
// Do this by first counting the number of keys,
// then creating an array big enough to hold them
// using the KeyList pointer.
FILETIME DummyFileTime;
DWORD DummyLength = MAX_PATH;
KeyCount = 0;
while (RegEnumKeyEx(
CurKey, KeyCount++, KeyName, & DummyLength,
NULL, NULL, NULL, & DummyFileTime
) != ERROR_NO_MORE_ITEMS)
{
DummyLength = MAX_PATH;
}
KeyList = new char*[KeyCount];
KeyCount = 0;
DummyLength = MAX_PATH;
while (RegEnumKeyEx(
CurKey, KeyCount, KeyName, & DummyLength,
NULL, NULL, NULL, & DummyFileTime
) != ERROR_NO_MORE_ITEMS)
{
KeyList[KeyCount] = new char[DummyLength+1];
strcpy(KeyList[KeyCount], KeyName);
DummyLength = MAX_PATH;
KeyCount++;
}
// Close the key
RegCloseKey(CurKey);
// Cycle through all keys; looking for a string valued subkey called
// 'HardWareKey' which is not NULL, and another subkey called 'Problem'
// whose fields are all valued 0.
for (DWORD KeyIndex=0; KeyIndex & lt; KeyCount; KeyIndex++)
{
bool HasProblem = false; // Is 'Problem' non-zero? Assume it is Ok
// Open the key
strcpy(KeyName, BASE_KEY);
strcat(KeyName, " \\ " );
strcat(KeyName, KeyList[KeyIndex]);
if (RegOpenKeyEx(
HKEY_DYN_DATA, KeyName, 0, KEY_PERMISSIONS, & CurKey
) != ERROR_SUCCESS)
continue;
// Test for a 0 valued Problem sub-key,
// which must only consist of raw data
DWORD DataType, DataSize;
RegQueryValueEx(CurKey, PROBLEM, NULL, & DataType, NULL, & DataSize);
if (DataType == REG_BINARY)
{
// We have a valid, binary " Problem " sub-key
// Test to see if the fields are zero
char HardwareSubKey[MAX_PATH];
// Data from the " Hardware " sub-key
BYTE *Data = new BYTE[DataSize];
// Data from " Problem " sub-key
// Read the data from the " Problem " sub-key
if (RegQueryValueEx(
CurKey, PROBLEM, NULL,
NULL, Data, & DataSize
) == ERROR_SUCCESS)
{
// See if it has any problems
for (DWORD index=0; index & lt; DataSize; index++)
HasProblem |= Data[index];
}
else
HasProblem = true; // No good
delete[] Data;
// Now try and read the Hardware sub-key
DataSize = MAX_PATH;
RegQueryValueEx(
CurKey, HARDWARE_KEY, NULL, & DataType, HardwareSubKey, & DataSize
);
if (DataType != REG_SZ)
HasProblem = true; // No good
// Do we have no problem, and a non-null Hardware sub-key?
if (!HasProblem & & strlen(HardwareSubKey) & gt; 0)
{
// Now open the key which is " pointed at " by HardwareSubKey
RegCloseKey(CurKey);
strcpy(KeyName, " Enum\\ " );
strcat(KeyName, HardwareSubKey);
if (RegOpenKeyEx(
HKEY_LOCAL_MACHINE, KeyName, 0, KEY_PERMISSIONS, & CurKey
) != ERROR_SUCCESS)
continue;
// Now read in the PortName and obtain the LPT number from it
char PortName[MAX_PATH];
DataSize = MAX_PATH;
RegQueryValueEx(
CurKey, PORTNAME, NULL, & DataType, PortName, & DataSize
);
if (DataType != REG_SZ)
strcpy(PortName, " " ); // No good
// Make sure it has LPT in it
if (strstr(PortName, " LPT " ) != NULL)
{
int PortNumber;
// The nubmer of the port
char PortNumberStr[MAX_PATH];
// Holds the number of the port as a string
WORD Allocation[64];
// Holds the registry data for the port address allocation
memset(PortNumberStr, '\0', MAX_PATH);
strncpy(PortNumberStr,
strstr(PortName, " LPT " )+3,
strlen(PortName)-(strstr(PortName, " LPT " )-PortName)-2);
// Find the port number
PortNumber = atoi(PortNumberStr);
// Find the address
RegCloseKey(CurKey);
strcpy(KeyName, BASE_KEY);
strcat(KeyName, " \\ " );
strcat(KeyName, KeyList[KeyIndex]);
RegOpenKeyEx(HKEY_DYN_DATA, KeyName, 0, KEY_PERMISSIONS, & CurKey);
DataSize = sizeof(Allocation);
RegQueryValueEx(
CurKey, ALLOCATION, NULL, & DataType,
(unsigned char*)Allocation, & DataSize
);
if (DataType == REG_BINARY)
{
// Decode the Allocation data: the port address is present
// directly after a 0x000C entry (which doesn't have 0x0000
// after it).
for (int pos=0; pos & lt; 63; pos++)
if (Allocation[pos] == 0x000C & &
Allocation[pos+1] != 0x0000 & &
PortNumber & lt; =MAX_LPT_PORTS)
{
// Found a port; add it to the list
FLPTAddress[PortNumber] = Allocation[pos+1];
FLPTCount++;
break;
}
}
}
}
}
RegCloseKey(CurKey);
}
// Destroy our key list
for (DWORD index=0; index & lt; =KeyCount; index++)
delete[] KeyList[index];
delete KeyList;
}
//---------------------------------------------------------------------------
// DetectPortsNT()
//---------------------------------------------------------------------------
void __fastcall TDLPrinterPortIOX::DetectPortsNT()
{
const char *BASE_KEY = " HARDWARE\\DEVICEMAP\\PARALLEL PORTS " ;
const char *LOADED_KEY = " HARDWARE\\RESOURCEMAP\\LOADED PARALLEL DRIVER RESOURCES\\Parport " ;
const char *DOS_DEVICES = " \\DosDevices\\LPT " ;
const char *DEVICE_PARALLEL = " \\Device\\Parallel " ;
const REGSAM KEY_PERMISSIONS = KEY_ENUMERATE_SUB_KEYS |
KEY_QUERY_VALUE;
HKEY CurKey; // Current key when using the registry
char KeyName[MAX_PATH]; // A key name when using the registry
char **ValueList; // List of value names
DWORD ValueCount; // Count of the number of value names in ValueList
// Clear the port count
FLPTCount = 0;
// Clear the port array
for (int index=0; index & lt; =MAX_LPT_PORTS; index++)
FLPTAddress[index] = 0;
// Open the registry
if (RegOpenKeyEx(
HKEY_LOCAL_MACHINE, BASE_KEY, 0, KEY_PERMISSIONS, & CurKey
) != ERROR_SUCCESS)
return; // Can't do anything without this BASE_KEY
// Grab all the value names under HKEY_LOCAL_MACHINE
//
// Do this by first counting the number of value names,
// then creating an array big enough to hold them
// using the ValueList pointer.
DWORD DummyLength = MAX_PATH;
DWORD ValueType;
ValueCount = 0;
while (RegEnumValue(
CurKey, ValueCount++, KeyName, & DummyLength,
NULL, & ValueType, NULL, NULL
) != ERROR_NO_MORE_ITEMS)
{
DummyLength = MAX_PATH;
}
ValueList = new char*[ValueCount];
ValueCount = 0;
DummyLength = MAX_PATH;
while (RegEnumValue(
CurKey, ValueCount, KeyName, & DummyLength,
NULL, & ValueType, NULL, NULL
) != ERROR_NO_MORE_ITEMS)
{
ValueList[ValueCount] = new char[DummyLength+1];
strcpy(ValueList[ValueCount], KeyName);
DummyLength = MAX_PATH;
ValueCount++;
}
// Close the key
RegCloseKey(CurKey);
for (DWORD index=0; index & lt; ValueCount; index++)
{
char DosDev[MAX_PATH]; // Key value for \DosDevices\LPT
DWORD DataType, DataSize; // Type and size of data read from the registry
// Is it a \DosDevices\LPT key?
strcpy(KeyName, BASE_KEY);
if (RegOpenKeyEx(
HKEY_LOCAL_MACHINE, KeyName, 0, KEY_PERMISSIONS, & CurKey
) == ERROR_SUCCESS)
{
DataSize = MAX_PATH;
RegQueryValueEx(
CurKey, ValueList[index], NULL, & DataType, DosDev, & DataSize
);
RegCloseKey(CurKey);
// Make sure it was a string
if (DataType != REG_SZ)
strcpy(DosDev, " " );
}
else
strcpy(DosDev, " " );
if (strstr(DosDev, DOS_DEVICES) != NULL)
{
int PortNumber; // The nubmer of the port
char PortNumberStr[MAX_PATH]; // String version of PortNumber
char PortIDStr[MAX_PATH]; // PortID
memset(PortNumberStr, '\0', MAX_PATH);
strncpy(PortNumberStr,
strstr(DosDev, DOS_DEVICES) + strlen(DOS_DEVICES),
strlen(DosDev) - (strstr(DosDev, DOS_DEVICES)-DosDev)
- strlen(DOS_DEVICES) + 1
);
// Get the Port ID
memset(PortIDStr, '\0', MAX_PATH);
strncpy(PortIDStr,
strstr(ValueList[index], DEVICE_PARALLEL) + strlen(DEVICE_PARALLEL),
strlen(ValueList[index])
- (strstr(ValueList[index], DEVICE_PARALLEL)-ValueList[index])
- strlen(DEVICE_PARALLEL) + 1
);
// Get the port number
PortNumber = atoi(PortNumberStr);
// Get the port address
RegOpenKeyEx(HKEY_LOCAL_MACHINE, LOADED_KEY, 0, KEY_PERMISSIONS, & CurKey);
strcpy(DosDev, " \\Device\\ParallelPort " );
strcat(DosDev, PortIDStr);
strcat(DosDev, " .Raw " );
if (RegQueryValueEx(
CurKey, DosDev, NULL, & DataType, NULL, NULL
) == ERROR_SUCCESS & &
DataType == REG_RESOURCE_LIST)
{
WORD Allocation[64]; // Binary data with port number inside
// Read in the binary data
DataSize = sizeof(Allocation);
RegQueryValueEx(
CurKey, DosDev, NULL, NULL,
(unsigned char*)Allocation, & DataSize
);
// Found a port; add it to the list
if (DataSize & gt; 0 & & PortNumber & lt; =MAX_LPT_PORTS)
{
FLPTAddress[PortNumber] = Allocation[12];
FLPTCount++;
}
}
RegCloseKey(CurKey);
}
}
// Destroy our key value list
// Destroy our key list
for (DWORD index=0; index & lt; =ValueCount; index++)
delete[] ValueList[index];
delete ValueList;
}
//---------------------------------------------------------------------------
// SetLPTNumber()
//---------------------------------------------------------------------------
void __fastcall TDLPrinterPortIOX::SetLPTNumber(BYTE Number)
{
// Note that we don't make sure it is within the range 1..FLPTCount
// because there _might_ (can someone claify this?) be a port numbered
// as #2, where it may be the _only_ port installed on the system.
if (Number & gt; 0 & & Number & lt; =MAX_LPT_PORTS)
{
FLPTNumber=Number;
FLPTBase=FLPTAddress[Number];
}
}
//---------------------------------------------------------------------------
// GetPin()
//---------------------------------------------------------------------------
bool __fastcall TDLPrinterPortIOX::GetPin(BYTE Index)
{
switch (Index)
{
case 1: return (Port[FLPTBase+2] & BIT0)==0; // Inverted
case 2: return (Port[FLPTBase] & BIT0)!=0;
case 3: return (Port[FLPTBase] & BIT1)!=0;
case 4: return (Port[FLPTBase] & BIT2)!=0;
case 5: return (Port[FLPTBase] & BIT3)!=0;
case 6: return (Port[FLPTBase] & BIT4)!=0;
case 7: return (Port[FLPTBase] & BIT5)!=0;
case 8: return (Port[FLPTBase] & BIT6)!=0;
case 9: return (Port[FLPTBase] & BIT7)!=0;
case 10: return (Port[FLPTBase+1] & BIT6)!=0;
case 11: return (Port[FLPTBase+1] & BIT7)==0; // Inverted
case 12: return (Port[FLPTBase+1] & BIT5)!=0;
case 13: return (Port[FLPTBase+1] & BIT4)!=0;
case 14: return (Port[FLPTBase+2] & BIT1)==0; // Inverted
case 15: return (Port[FLPTBase+1] & BIT3)!=0;
case 16: return (Port[FLPTBase+2] & BIT2)!=0;
case 17: return (Port[FLPTBase+2] & BIT3)==0; // Inverted
default: return false; // pins 18-25 (GND), and other invalid pins
}
}
//---------------------------------------------------------------------------
// SetPin()
//---------------------------------------------------------------------------
void __fastcall TDLPrinterPortIOX::SetPin(BYTE Index, bool State)
{
if (State)
switch (Index)
{
case 1: Port[FLPTBase+2] & =~BIT0; break; // Inverted
case 2: Port[FLPTBase]|=BIT0; break;
case 3: Port[FLPTBase]|=BIT1; break;
case 4: Port[FLPTBase]|=BIT2; break;
case 5: Port[FLPTBase]|=BIT3; break;
case 6: Port[FLPTBase]|=BIT4; break;
case 7: Port[FLPTBase]|=BIT5; break;
case 8: Port[FLPTBase]|=BIT6; break;
case 9: Port[FLPTBase]|=BIT7; break;
/*
case 10: Port[FLPTBase+1]|=BIT6; break;
case 11: Port[FLPTBase+1] & =~BIT7; break; // Inverted
case 12: Port[FLPTBase+1]|=BIT5; break;
case 13: Port[FLPTBase+1]|=BIT4; break;
*/
case 14: Port[FLPTBase+2] & =~BIT1; break; // Inverted
/*
case 15: Port[FLPTBase+1]|=BIT3; break;
*/
case 16: Port[FLPTBase+2]|=BIT2; break;
case 17: Port[FLPTBase+2] & =~BIT3; break; // Inverted
default: break; // pins 18-25 (GND), and other invalid pins
}
else
switch (Index)
{
case 1: Port[FLPTBase+2]|=BIT0; break; // Inverted
case 2: Port[FLPTBase] & =~BIT0; break;
case 3: Port[FLPTBase] & =~BIT1; break;
case 4: Port[FLPTBase] & =~BIT2; break;
case 5: Port[FLPTBase] & =~BIT3; break;
case 6: Port[FLPTBase] & =~BIT4; break;
case 7: Port[FLPTBase] & =~BIT5; break;
case 8: Port[FLPTBase] & =~BIT6; break;
case 9: Port[FLPTBase] & =~BIT7; break;
/*
case 10: Port[FLPTBase+1] & =~BIT6; break;
case 11: Port[FLPTBase+1]|=BIT7; break; // Inverted
case 12: Port[FLPTBase+1] & =~BIT5; break;
case 13: Port[FLPTBase+1] & =~BIT4; break;
*/
case 14: Port[FLPTBase+2]|=BIT1; break; // Inverted
/*
case 15: Port[FLPTBase+1] & =~BIT3; break;
*/
case 16: Port[FLPTBase+2] & =~BIT2; break;
case 17: Port[FLPTBase+2]|=BIT3; break; // Inverted
default: break; // pins 18-25 (GND), and other invalid pins
}
}
//---------------------------------------------------------------------------
// LPTPrintChar
// Sends a character to the printer.
// Returns true on success. Repeat as neccessary.
//---------------------------------------------------------------------------
bool __fastcall TDLPrinterPortIOX::LPTPrintChar(char Ch)
{
// Write data to Base+0
Port[FLPTBase]=(BYTE)Ch;
// Write 0Dh to Base+2.
Port[FLPTBase+2]=0x0D;
// Make sure there's a delay of at least one microsecond
Sleep(1);
// Write 0Ch to Base+2.
Port[FLPTBase+2]=0x0C;
// Input from Base+1 and check if Bit 7 is 1.
// Return this status as whether the character was printed
return (Port[FLPTBase+1] & BIT7)!=0;
}
//---------------------------------------------------------------------------
namespace Dlportiox
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[2] = {__classid(TDLPortIOX),
__classid(TDLPrinterPortIOX)};
RegisterComponents( " DiskDude " , classes, 1);
}
}
#pragma package(smart_init)
//*** TDLPortIOX: DriverLINX Port IO Driver wrapper OCX **********************
//** **
//** File: DLPortIOX.cpp **
//** **
//** Copyright (c) 1999 John Pappas (DiskDude). All rights reserved. **
//** This software is FreeWare. **
//** **
//** Please notify me if you make any changes to this file. **
//** Email: diskdude@poboxes.com **
//** **
//*** http://diskdude.cjb.net/ ***********************************************
#include & lt; vcl.h & gt;
#pragma hdrstop
USERES( " DLPortIOX.res " );
USERES( " DLPortIOX.dcr " );
USEPACKAGE( " VCL35.bpi " );
USEUNIT( " TDLPortIOX.cpp " );
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Package source.
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1;
}
#include & lt; vcl.h & gt;
#pragma hdrstop
#include & lt; atl\atlvcl.h & gt;
#include " DLPrinterPortIOImpl.h "
#pragma package(smart_init)
USERES( " DLPrinterPortIOXControl.res " );
USEUNIT( " DLPrinterPortIOXControl_ATL.cpp " );
USETLB( " DLPrinterPortIOXControl.tlb " );
USEUNIT( " DLPrinterPortIOXControl_TLB.cpp " );
USEUNIT( " DLPrinterPortIOImpl.cpp " ); /* DLPrinterPortIOX: CoClass */
USEFORM( " About.cpp " , DLPrinterPortIOXAbout);
//---------------------------------------------------------------------------
TComModule DLPrinterPortIOXControl1Module;
TComModule & _Module = DLPrinterPortIOXControl1Module;
// The ATL Object map holds an array of _ATL_OBJMAP_ENTRY structures that
// described the objects of your OLE server. The MAP is handed to your
// project's CComModule-derived _Module object via the Init method.
//
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_DLPrinterPortIOX, TDLPrinterPortIOXImpl)
END_OBJECT_MAP()
// Entry point of your Server invoked by Windows for processes or threads are
// initialized or terminated.
//
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
if (reason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hinst);
DisableThreadLibraryCalls(hinst);
}
return TRUE;
}
// _Module.Term is typically invoked from the DLL_PROCESS_DETACH of your
// DllEntryPoint. However, this may result in an incorrect shutdown sequence.
// Instead an Exit routine is setup to invoke the cleanup routine
// CComModule::Term.
//
void ModuleTerm(void)
{
_Module.Term();
}
#pragma exit ModuleTerm 63
// Entry point of your Server invoked to inquire whether the DLL is no
// longer in use and should be unloaded.
//
STDAPI __export DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
// Entry point of your Server allowing OLE to retrieve a class object from
// your Server
//
STDAPI __export DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
// Entry point of your Server invoked to instruct the server to create
// registry entries for all classes supported by the module
//
STDAPI __export DllRegisterServer(void)
{
return _Module.RegisterServer(TRUE);
}
// Entry point of your Server invoked to instruct the server to remove
// all registry entries created through DllRegisterServer.
//
STDAPI __export DllUnregisterServer(void)
{
return _Module.UnregisterServer();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include & lt; vcl.h & gt;
#pragma hdrstop
#include & lt; atl\atlvcl.h & gt;
#include " DLPrinterPortIOImpl.h "
#include " About.h "
//---------------------------------------------------------------------------
#pragma link " TDLPortIOX "
#pragma package(smart_init)
STDMETHODIMP TDLPrinterPortIOXImpl::AboutBox()
{
try
{
ShowDLPrinterPortIOXAbout();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ClassNameIs(BSTR string,
VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; ClassNameIs(string);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::CloseDriver()
{
try
{
m_VclCtl- & gt; CloseDriver();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_ActiveHW(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; ActiveHW;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_Cursor(short* Value)
{
try
{
*Value = (short)(m_VclCtl- & gt; Cursor);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_DLLPath(BSTR* Value)
{
try
{
*Value = WideString(m_VclCtl- & gt; DLLPath).Copy();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_DriverPath(BSTR* Value)
{
try
{
*Value = WideString(m_VclCtl- & gt; DriverPath).Copy();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_Enabled(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; Enabled;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_HardAccess(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; HardAccess;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LastError(BSTR* Value)
{
try
{
*Value = WideString(m_VclCtl- & gt; LastError).Copy();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTAckwl(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTAckwl;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTBasePort(short* Value)
{
try
{
*Value = (short)(m_VclCtl- & gt; LPTBasePort);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTBusy(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTBusy;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTError(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTError;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTNumber(unsigned char* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTNumber;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTNumPorts(unsigned char* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTNumPorts;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTPaperEnd(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTPaperEnd;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_LPTSlct(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTSlct;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::get_Visible(VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; Visible;
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::GetPin(unsigned char Index,
VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; GetPin(Index);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::LPTAutofd(VARIANT_BOOL Flag)
{
try
{
m_VclCtl- & gt; LPTAutofd(Flag);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::LPTInit()
{
try
{
m_VclCtl- & gt; LPTInit();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::LPTPrintChar(short Ch,
VARIANT_BOOL* Value)
{
try
{
*Value = m_VclCtl- & gt; LPTPrintChar(Ch);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::LPTSlctIn()
{
try
{
m_VclCtl- & gt; LPTSlctIn();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::LPTStrobe()
{
try
{
m_VclCtl- & gt; LPTStrobe();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::OpenDriver()
{
try
{
m_VclCtl- & gt; OpenDriver();
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ReadLPortFIFO(short PortAddr,
short NumPorts, long Buffer)
{
try
{
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ReadPort(short Address,
unsigned char* Value)
{
try
{
*Value = m_VclCtl- & gt; ReadPort(Address);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ReadPortFIFO(short PortAddr,
short NumPorts, unsigned char Buffer)
{
try
{
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ReadPortL(short Address, long* Value)
{
try
{
*Value = m_VclCtl- & gt; ReadPortL(Address);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ReadPortW(short Address, short* Value)
{
try
{
*Value = m_VclCtl- & gt; ReadPortW(Address);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::ReadWPortFIFO(short PortAddr,
short NumPorts, short Buffer)
{
try
{
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_Cursor(short Value)
{
try
{
const DISPID dispid = 38;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; Cursor = (TCursor)(Value);
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_DLLPath(BSTR Value)
{
try
{
const DISPID dispid = 31;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; DLLPath = AnsiString(Value);
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_DriverPath(BSTR Value)
{
try
{
const DISPID dispid = 30;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; DriverPath = AnsiString(Value);
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_Enabled(VARIANT_BOOL Value)
{
try
{
const DISPID dispid = -514;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; Enabled = Value;
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_HardAccess(VARIANT_BOOL Value)
{
try
{
const DISPID dispid = 33;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; HardAccess = Value;
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_LPTNumber(unsigned char Value)
{
try
{
const DISPID dispid = 14;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; LPTNumber = Value;
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::set_Visible(VARIANT_BOOL Value)
{
try
{
const DISPID dispid = 37;
if (FireOnRequestEdit(dispid) == S_FALSE)
return S_FALSE;
m_VclCtl- & gt; Visible = Value;
FireOnChanged(dispid);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::SetPin(unsigned char Index,
VARIANT_BOOL State)
{
try
{
m_VclCtl- & gt; SetPin(Index, State);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::WriteLPortFIFO(short PortAddr,
short NumPorts, long Buffer)
{
try
{
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::WritePort(short Address,
unsigned char Data)
{
try
{
m_VclCtl- & gt; WritePort(Address, Data);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::WritePortFIFO(short PortAddr,
short NumPorts, unsigned char Buffer)
{
try
{
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::WritePortL(short Address, long Data)
{
try
{
m_VclCtl- & gt; WritePortL(Address, Data);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::WritePortW(short Address, short Data)
{
try
{
m_VclCtl- & gt; WritePortW(Address, Data);
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
STDMETHODIMP TDLPrinterPortIOXImpl::WriteWPortFIFO(short PortAddr,
short NumPorts, short Buffer)
{
try
{
}
catch(Exception & e)
{
return Error(e.Message.c_str(), IID_IDLPrinterPortIOX);
}
return S_OK;
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include & lt; vcl.h & gt;
#pragma hdrstop
#include " DLPrinterPortIOXControl_ATL.h "
#ifdef _ATL_STATIC_REGISTRY
#include & lt; statreg.h & gt;
#include & lt; statreg.cpp & gt;
#endif
#include & lt; atlimpl.cpp & gt;
#include & lt; atlctl.cpp & gt;
#if defined(USING_ATLVCL)
#include & lt; atlvcl.cpp & gt;
#else
#include & lt; atlwin.cpp & gt;
#endif
//---------------------------------------------------------------------------
#pragma package(smart_init)