Sample Project

This page explains the functions of AHid.dll on the basis of a C++ console application. You find the corresponding sample project in the Downloads on our welcome page (Visual Studio 2010, C++ Console).

There are many more sample projects on the welcome page with the following common: They all implemented a Graphical User Interface (GUI)!

Figure 1: The HID device parameters

In principle, this is not a bad idea. But all the functions to handle the controls and their values do polute the source code. This makes it difficult to understand the basic concepts of AHid.dll. Therefore, it is recommended to read the following sections entirely!

Keep connection state up-to-date

The console application does not have a Windows Message Queue. But it is essential to know, if your HID device is currently connected to USB or not.

In normal case, using Windows messaging, you can handle the WM_DEVICECHANGE messge by calling AHid_Find() function. The AHid_Find() function searches for your device on USB and you can use it to keep the connection state up-to-date.

In the console application, we go another way by calling is_connected() function on each loop.

Figure 2: Main loop

And as you can see, is_connected() also just calls AHid_Find().

Figure 3: The functions of AHid.dll

The entire program has a typical sequence. First, AHid.dll is initialized by a call to AHid_Init(). Here, you can also create the data pipes to your HID device by two calls to AHid_Register().

In the upcoming main loop, the keypress is evaluated and depending on the HID device connection state, the AHid_Read() or AHid_Write() functions are performed to read from your device or to write to.

Finally, you should call AHid_Deregister() to release the allocated resources.

There are two more function available: AHid_Info() and AHid_Identify().

AHid_Info() only displays a message box with the version number of AHid.dll.
AHid_Identify() returns the device path of your HID device. You can use it to combine different data pipes from one HID device. The device path of an HID device is unique. Therefore, only the data pipes from this device have the same device path. The device path is a string value combination of the VID and PID from your HID device and the USB port that it is connected to. You can also find the device path in the Windows Hardware Manager.

More informations about all functions of AHid.dll can be found here.

If you have further questions on this topic, please drop us a line.