Search by Tags

Oak in Visual Basic .NET and C Sharp

 
Applicable for
oak


Compare with Revision

Subscribe for this article updates

Introduction

Toradex provides a programming library named OakLib for Windows. This library contains a set of functions making it easy for developers to access their Oak devices. The library is provided as a Windows DLL, a library file and C header file, which is the most common way of distributing a library on the Windows platform. Using the OakLib in a C or C++ application is very easy. However, you may be using a different programming language. This article will show you, how to use the OakLib with Visual Basic .NET and C#.

Principles

Many programming language offer the possibility to call functions that are in a Windows DLL. Each language has its own methods, but the underlying principles are the same.

  • You have to provide in your language an equivalent for the C data structures that are declared in the Oak.h header file.
  • You have to declare in your language the functions from the OakLib that you plan to use and instruct your compiler that these functions are located in the OakLib DLL.

Sample Code

The sample projects are Visual Studio 2008 solutions that are ports of the OakLibTest_HotPlug C application. The source code is commented to help you understand how things work.

Download the sample project for Visual Basic .NET

Download the sample project for C#

FAQ

What about unicode ?

The source code covers only the ASCII version of the OakLib library. It can be very easily modified to use the Unicode version of the library.

Why do the function names have a "_a" prefix ?

The OakLib ships in two versions, the ASCII and the Unicode version. In order to make it possible to use both version in a single application, the OakLib define function name aliases depending on whether you are compiling in ASCII or Unicode version. When using the ascii version a function name like Oak_FindSensor() is actually an alias to Oak_FindSensor_a(), and when compiling in Unicode mode it is an alias to Oak_FindSensor_w(). As the sample code does not define such aliases, you have the use the actual function name.

Can you provide sample code for VB6 ?

VB6 is deprecated (Microsoft's extended support ended in March 2008), and we do not support it. However, like it successor version, VB6 applications can call DLL functions.

What about other programming languages ?

We do not provide support for additional programming languages. If your language can call function from Windows DLL, you probably can use the OakLib.