Microsoft KB Archive/154819

= How To Access PC Bus Devices in Visual Basic for Windows =

Article ID: 154819

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q154819



SUMMARY
This article describes how to access PC bus devices in Visual Basic for Windows. Many programs written in MS-DOS versions of BASIC used Peek, Poke, and In and Out to access the PC bus directly. This functionality is not supported in Visual Basic for Windows.



MORE INFORMATION
MS-DOS did not implement any memory protection; this meant that BASIC applications were able to write to any memory location directly, giving fast access to the hardware of the PC, including custom hardware that plugged into the expansion ports. In a multitasking environment it was clearly unacceptable for an application to write to memory owned by another application. The hardware port addresses are deemed to belong to the system. Accordingly, applications are unable to write directly to the PC bus addresses.

It is often desirable to port MS-DOS BASIC code to a Windows environment. However, programs that attempt to control custom devices will fail to port directly.

Effectively, there are two potential solutions:


 * 1) Use a custom Virtual Device Driver (VxD). It is likely that the manufacturers of more popular custom devices will have a VxD. However, there may be no VxD, or the VxD interface may be structured differently.

Versions of Visual Basic prior to 5.0 may require extra steps to use a VxD. Versions prior to 5.0 did not have the AddressOf operator needed by many VxDs to use Callback procedures. The workaround is have the Visual Basic program call a C DLL which would in turn call the VxD.
 * 1) Use a third-party DLL or OCX that emulates the functionality. There are a number available commercially or as shareware.

