WinIo v3.0

Direct Hardware Access Under Windows NT/2000/XP/2003/Vista/7/2008
Copyright 1998-2010 Yariv Kaplan
www.internals.com

The WinIo library allows 32-bit and 64-bit Windows applications to directly access I/O ports and physical memory.

Version 3.0 offers the following features:

  • Supports 32-bit and 64-bit platforms (Itanium excluded).
  • WinIo can now be used by multiple applications concurrently.
  • New C# samples.
Bug fixes in this version:
  • Fixed a bug that prevented accessing physical memory above 2GB.
  • Fixed a bug that led to the WinIo driver getting uninstalled when calling ShutdownWinIo if the driver was set to load during boot with InstallWinIoDriver.
Note: Support for Windows 9x/ME has been removed. If you need to support these operating systems, please use WinIo v2.


InitializeWinIo

This function initializes the WinIo library.

bool _stdcall InitializeWinIo();

Parameters

None

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The InitializeWinIo function must be called before using any other function in the library.

Note:

  • A typical reason for getting an error from this call is if the WinIo files are not located in the same directory as the application's executable file.
  • There is no need to invoke the InitializeWinIo function before calling the InstallWinIoDriver and RemoveWinIoDriver functions.
  • Under 32-bit Windows, calling InitializeWinIo grants the caller full access to the I/O address space. Following a call to this function, an application is free to use the _inp/_outp functions provided by the run-time library to access I/O ports on the system.


ShutdownWinIo

This function performs cleanup of the WinIo library.

void _stdcall ShutdownWinIo();

Parameters

None

Return Values

None

Remarks

The ShutdownWinIo function must be called before terminating the application or in case the WinIo library is no longer required. This function shuts down the WinIo library and frees the resources which were allocated by a call to the InitializeWinIo function.


InstallWinIoDriver

This function installs the WinIo driver on the system.

bool _stdcall InstallWinIoDriver(
   PSTR pszWinIoDriverPath,
   bool IsDemandLoaded
);

Parameters

pszWinIoDriverPath
[in] Pointer to a null-terminated string that specifies the full path to the WinIo driver. This should either be WinIo32.sys or WinIo64.sys depending on the underlying platform.

IsDemandLoaded
[in] This parameter must be set to false.

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The InstallWinIoDriver function installs the WinIo driver and configures it to load automatically when Windows starts. This function fails if called from a non-administrative account.


RemoveWinIoDriver

This function removes the WinIo driver from the system.

bool _stdcall RemoveWinIoDriver();

Parameters

None

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The RemoveWinIoDriver function removes the WinIo driver. This function fails if called from a non-administrative account.


GetPortVal

This function reads a BYTE/WORD/DWORD value from an I/O port.

bool _stdcall GetPortVal(
   WORD wPortAddr,
   PDWORD pdwPortVal,
   BYTE bSize
);

Parameters

wPortAddr
[in] I/O port address

pdwPortVal
[out] Pointer to a DWORD variable that receives the value obtained from the port.

bSize
[in] Number of bytes to read.
Can be 1 (BYTE), 2 (WORD) or 4 (DWORD).

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The GetPortVal function reads a byte, a word or a double word from the specified I/O port.


SetPortVal

This function writes a BYTE/WORD/DWORD value to an I/O port.

bool _stdcall SetPortVal(
   WORD wPortAddr,
   DWORD dwPortVal,
   BYTE bSize
);

Parameters

wPortAddr
[in] I/O port address

dwPortVal
[in] Value to be written to the port

bSize
[in] Number of bytes to write.
Can be 1 (BYTE), 2 (WORD) or 4 (DWORD).

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The SetPortVal function writes a byte, a word or a double word to the specified I/O port.


GetPhysLong

This function reads a double word from the specified physical memory location.

bool _stdcall GetPhysLong(
   PBYTE pbPhysAddr,
   PDWORD pdwPhysVal
);

Parameters

pbPhysAddr
[in] Pointer to the physical address

pdwPhysVal
[out] Pointer to a DWORD variable that receives the value obtained from the physical memory location.

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The GetPhysLong function reads a 32-bit value from the specified physical memory location.


SetPhysLong

This function writes a double word to the specified physical memory location.

bool _stdcall SetPhysLong(
   PBYTE pbPhysAddr,
   DWORD dwPhysVal
);

Parameters

pbPhysAddr
[in] Pointer to the physical address

dwPhysVal
[in] Specifies a DWORD value to be written to the physical memory location.

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The SetPhysLong function writes a 32-bit value to the specified physical memory location.


MapPhysToLin

This function maps a region of physical memory into the linear address space of the application.

PBYTE _stdcall MapPhysToLin(

   tagPhysStruct &PhysStruct
);

Parameters

PhysStruct
[in] A reference to a tagPhysStruct structure that is initialized by the caller with the following values:

pvPhysAddr - Physical address to be mapped. This is a 64-bit value on both 32-bit and 64-bit systems. On 32-bit Windows, the lower 32 bits of this variable must be set to zero.
dwPhysMemSizeInBytes - Number of bytes to map.

Return Values

If the function succeeds, the return value is the linear address corresponding to the physical address that was passed in pvPhysAddr. Otherwise, the return value is NULL.

Remarks

The MapPhysToLin function maps a region of physical memory into the linear address space of the calling application.


UnmapPhysicalMemory

This function unmaps a region of physical memory which was previously mapped to the linear address space of the application using the MapPhysToLin function.

bool _stdcall UnmapPhysicalMemory(

   tagPhysStruct &PhysStruct
);

Parameters

PhysStruct
[in] Handle to the physical memory section which was returned from the call to the MapPhysToLin function.

Return Values

If the function succeeds, the return value is true. Otherwise, the function returns false.

Remarks

The UnmapPhysicalMemory function unmaps a region of physical memory which was previously mapped to the linear address space of the application using the MapPhysToLin function.


Software License Agreement for WinIo

The following terms apply to all files associated with the software unless explicitly disclaimed in individual files.

IMPORTANT- PLEASE READ CAREFULLY: BY INSTALLING THE SOFTWARE (AS DEFINED BELOW), OR COPYING THE SOFTWARE, YOU (EITHER ON BEHALF OF YOURSELF AS AN INDIVIDUAL OR ON BEHALF OF AN ENTITY AS ITS AUTHORIZED REPRESENTATIVE) AGREE TO ALL OF THE TERMS OF THIS END USER LICENSE AGREEMENT ("AGREEMENT") REGARDING YOUR USE OF THE SOFTWARE. IF YOU DO NOT AGREE WITH ALL OF THE TERMS OF THIS AGREEMENT, DO NOT INSTALL, COPY OR OTHERWISE USE THE SOFTWARE.

1. GRANT OF LICENSE: Subject to the terms below, Yariv Kaplan ("AUTHOR") hereby grants you a non-exclusive, non-transferable, non-assignable license to install and to use the downloadable version of WinIo ("SOFTWARE").

a. Redistributable Code. Permission is hereby granted to you, free of charge, to reproduce and distribute the object code form of the SOFTWARE solely in conjunction with, and as part of, your application ("Permitted Application"); provided that you comply with the following:

If you redistribute any portion of the Redistributable Code, you agree that: (i) you will only distribute the Redistributable Code in conjunction with, and as part of, your Permitted Application which adds significant functionality to the Redistributable Code and that distribution of the Permitted Application does not compete with the AUTHOR's distribution of the SOFTWARE; (ii) you will include a valid copyright notice on your Permitted Application; (iii) you will not permit further redistribution of the Redistributable Code; and (iv) you will indemnify, hold harmless, and defend the AUTHOR from and against any claims or lawsuits, including attorneys' fees, that arise or result from the use or distribution of your Permitted Application.

b. License to use Source Code. You may not sell, lease, rent, transfer or sublicense the source code of this SOFTWARE.

2. MODIFICATION: SOFTWARE Source Code may be modified without the prior written permission of the AUTHOR. Any modifications made to the SOFTWARE will continue to be subject to the terms and conditions of this AGREEMENT.

3. COPYRIGHT: All rights, title, and copyrights in and to the SOFTWARE and any copies of the SOFTWARE are owned by the AUTHOR. The SOFTWARE is protected by copyright laws and international treaty provisions. Therefore, you must treat the SOFTWARE like any other copyrighted material.

4. TITLE: You acknowledge that no title to the intellectual property in the SOFTWARE is transferred to you. Title, ownership, rights, and intellectual property rights in and to the SOFTWARE shall remain the exclusive property of the AUTHOR. The SOFTWARE is protected by copyright laws of the United States and international treaties.

5. LIMITATION OF LIABILITY: You must assume the entire risk of using the SOFTWARE.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHOR HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


Using WinIo in a C++ Builder application

In order to use WinIo in a C++ Builder application, you should take the following steps:

  1. Place winio.dll, winio.vxd and winio.sys in the directory where your application's executable file resides.
  2. Create a winio.lib file by running the IMPLIB utility that is bundled with C++ Builder.
  3. Add the generated winio.lib to your project file.
  4. Remove the WINIO_API constant from the function declarations in winio.h.
  5. Add the "#include "winio.h" statement to your source file.
  6. Call InitializeWinIo.
  7. Call the library's functions to access I/O ports and physical memory.
  8. Call ShutdownWinIo.


Using WinIo from a non-administrative account

WinIo can now be used from non-administrative accounts under Windows NT/2000/XP. In order to support this configuration, the WinIo driver (winio.sys) must be first installed on the system from an administrative account using the InstallWinIoDriver function, which is provided by the library. Following installation, the driver will load automatically whenever Windows starts. An application will then be able to use the library's functions to access I/O ports and physical memory.

You should take the following steps in order to use WinIo from a non-administrative account:

  1. Place winio.dll, winio.vxd and winio.sys in the directory where your application resides.
  2. Log on as an administrator.
  3. Call InstallWinIoDriver with the first parameter set to the path of the winio.sys file (e.g. c:\myapp\winio.sys).
  4. Reboot the system.
  5. Log on as a regular user.
  6. You should now be able to use WinIo in the same way as when using the library from an administrative account.
  7. When WinIo is no longer required, call RemoveWinIoDriver to remove the WinIo driver from the system. This must be performed from an administrative account.


Using WinIo in a Visual Basic application

In order to use WinIo in a Visual Basic application, you should take the following steps:

  1. Place winio.dll, winio.vxd and winio.sys in the directory where your application's executable file resides.
  2. Add winio.bas to your project file.
  3. Call InitializeWinIo.
  4. Call the library's functions to access I/O ports and physical memory.
  5. Call ShutdownWinIo.


Using WinIo in a Visual C++ application

In order to use WinIo in a Visual C++ application, you should take the following steps:

  1. Place winio.dll, winio.vxd and winio.sys in the directory where your application's executable file resides.
  2. Add winio.lib to your project file by right clicking on the project name in the Visual C++ workview pane and selecting "Add Files to Project...".
  3. Add the #include "winio.h" statement to your source file.
  4. Call InitializeWinIo.
  5. Call the library's functions to access I/O ports and physical memory.
  6. Call ShutdownWinIo.