Vous êtes sur la page 1sur 2

Parallel Port Programming in VB 1

PARALLEL PORT PROGRAMMING IN VB


This article describes how to design a VB 6.0 code to communicate with hardware
ports like parallel port. For communicating with hardware ports you have to design your own
Device Driver (Windows DLL) in Visual C++ 6.0. After DLL is created you can use that DLL file
in your Visual Basic project to communicate with parallel port.
Here I will not explain you how to start with VC++ or VB programming. I consider
here that the reader is familiar with both the languages Visual Basic and Visual C++.
For my convenience I have explained the coding with Microsoft Visual C++ and Visual
Basic languages of Version 6.0.

Starting with DLL programming:


You have to create 2 files in VC++ 6.0. The first is a DEF (definition file). The second is the
CPP (C++ source) file. Open VC++ and take a text editor and create below files and save
them in a separate directory for example C:\VBPORT\.

File number 1: Definition Files (* .def)


File Name: vbport.def

LIBRARY 8255
DESCRIPTION DLL FOR IO CARD

EXPORTS
Send_To_OutPut_Port @1

The name of your DLL library is given on the first line. It is “vbport”. The second line is just a
comment. Exports list the names of the functions you will eventually define in your VC++.
Here i have used one function called “Send_To_OutPut_Port”. If you want to declare some
more functions then declare them as Your_Function_Name @ Next_Number in Exports Lists.
For example if you have another function called “Get_From_Input_Port” then declare it in
exports as “Get_From_Input_Port @ 2”.

File number 2: VC++ Source Files (* .cpp)


File Name: vbport.cpp

#include &ltstdio.h>
#include &ltconio.h>

short _stdcall Send_To_OutPut_Port(int PortAddress, int PortData)


{
short Dummy;
Dummy = (short)(_outp(PortAddress, PortData));
return(Dummy);
};

#include &ltconio.h> is the file where “_outp” is defined.

1. Once above coding is done follow these steps.


2. Open VC++. Choose File menu> New.
3. Make sure “Projects” tab is selected in a New window.
4. Choose last option “Win32 Dynamic Link Library”.
5. Give the location as C:\VBPORT\ where we have stored our .def and .cpp file.
6. Give a name for your project “vbport”.
7. Click OK.
8. Choose “Simple DLL project” from the popup window and click Finish.
9. Now you can see a new class library on your left window workspace.
10. Choose “file view” on Work space at the bottom.
11. Click on Source files and make sure both .cpp and .def files are added.

Programmer: Kiran P
Parallel Port Programming in VB 2

12. If not added then add them manually.


13. Now save the workspace.
14. Click on Build Button on top.
15. That’s over your activity with VC++.
16. Open C:\VBPORT\VBPORT\debug\
17. Copy “vbport.dll” file to C:\WINDOWS\
That is done with your Library.

Now accessing your DLL in Visual Basic Projects:


Now in Visual Basic 6.0 choose Standard EXE project and start coding below.

Add these two components to your design window,


Text Box: txt_data
Command Button: cmd_send

Option Explicit
Dim out_port_add As Integer
Dim dummy_var As Integer

Private Declare Function Send_To_OutPut_Port Lib "vbio.dll" _


(ByVal PortAddress As Integer, _
ByVal PortData As Integer) As Integer

Private Sub cmd_send_Click()


out_port_add = 888
dummy_var = Send_To_OutPut_Port(out_port_add, txt_data.Text)
End Sub

Yes, it has to work. If you have installed printer you can check the output.

Programmer: Kiran P

Vous aimerez peut-être aussi