Vjoy Feeder SDK: Version 2.0.5 Release - January 2015
Vjoy Feeder SDK: Version 2.0.5 Release - January 2015
Vjoy Feeder SDK: Version 2.0.5 Release - January 2015
Table of Contents
vJoy Feeder SDK..............................................................................................................................................................1
Files listing:..................................................................................................................................................................1
Fundamentals:..............................................................................................................................................................3
Recommended Practices:.............................................................................................................................................4
Test vJoy Driver:.....................................................................................................................................................4
Test Interface DLL matches vJoy Driver:................................................................................................................4
Test vJoy Virtual Devices:.......................................................................................................................................5
Acquire the vJoy Device:........................................................................................................................................8
Feed vJoy Device:...................................................................................................................................................8
Relinquish the vJoy Device:..................................................................................................................................10
Interface Function Reference:....................................................................................................................................11
General driver data................................................................................................................................................11
Write access to vJoy Device..................................................................................................................................11
vJoy Device properties..........................................................................................................................................12
Robust write access to vJoy Devices.....................................................................................................................13
Build & Deploy:.........................................................................................................................................................14
Location of Feeder.................................................................................................................................................14
Location of vJoyInterface.dll.................................................................................................................................14
Logging [2.0.5]...........................................................................................................................................................14
Start/Stop Logging.................................................................................................................................................15
Log File..................................................................................................................................................................16
This SDK includes all that is needed to write a feeder for vJoy version 2.0.5
Check for the latest SDK.
Files listing:
inc Include folder
inc\public.h vJoy general public definitions
inc\vjoyinterface.h Interface function declaration for vJoyInterface.dll
c# C# SDK folder
x86 Library folder (x86) folder
x64 Library folder (x64) folder
WrapperTest Demo Wrapper Project (Visual Studio 2008 Express) folder
ReadMe.pdf C# SDK Read Me file
Fundamentals:
This interface and example will enable you to write a C/C++ vJoy feeder.
Features introduced in version 2.0.5 are marked with [2.0.5]
To write a C# refer to ReadMe file in C# folder.
It is advisable to start your feeder from the supplied example and make the needed changes. Here are the five basic
steps you might want to follow:
Test Driver: Check that the driver is installed and enabled.
Obtain information about the driver.
An installed driver implies at least one vJoy device.
[2.0.5] Test if driver matches interface DLL file
Test Virtual Device(s): Get information regarding one or more devices.
Read information about a specific device capabilities: Axes, buttons and POV hat
switches.
Device acquisition: Obtain status of a vJoy device.
Acquire the device if the device status is owned or is free.
Updating: Inject position data to a device (as long as the device is owned by the feeder).
Position data includes the position of the axes, state of the buttons and state of the POV hat
switches.
Relinquishing the The device is owned by the feeder and cannot be fed by another application until
device: relinquished.
Recommended Practices:
Test vJoy Driver:
Before you start, check if the vJoy driver is installed and check that it is what you expected:
// Get the driver attributes (Vendor ID, Product ID, Version Number)
if (!vJoyEnabled())
{
_tprintf("Failed Getting vJoy attributes.\n");
return -2;
}
else
{
_tprintf("Vendor: %S\nProduct :%S\nVersion Number:%S\n",\
TEXT(GetvJoyManufacturerString()),\
TEXT(GetvJoyProductString()),\
TEXT(GetvJoySerialNumberString()));
};
If you are not interested in the actual values of the respective version numbers, you can simplify your code by passing
NULL to both function parameters.
Test vJoy Virtual Devices:
Check which devices are installed and what their state is it:
// Get the state of the requested device
VjdStat status = GetVJDStatus(iInterface);
switch (status)
{
case VJD_STAT_OWN:
_tprintf("vJoy Device %d is already owned by this feeder\n", iInterface);
break;
case VJD_STAT_FREE:
_tprintf("vJoy Device %d is free\n", iInterface);
break;
case VJD_STAT_BUSY:
_tprintf("vJoy Device %d is already owned by another feeder\nCannot continue\n",
iInterface);
return -3;
case VJD_STAT_MISS:
_tprintf("vJoy Device %d is not installed or disabled\nCannot continue\n",
iInterface);
return -4;
default:
_tprintf("vJoy Device %d general error\nCannot continue\n", iInterface);
return -1;
};
Now make sure that the axes, buttons (and POV hat switches) are as expected:
// Check which axes are supported
BOOL AxisX = GetVJDAxisExist(iInterface, HID_USAGE_X);
BOOL AxisY = GetVJDAxisExist(iInterface, HID_USAGE_Y);
BOOL AxisZ = GetVJDAxisExist(iInterface, HID_USAGE_Z);
BOOL AxisRX = GetVJDAxisExist(iInterface, HID_USAGE_RX);
// Get the number of buttons supported by this vJoy device
int nButtons = GetVJDButtonNumber(iInterface);
// Print results
_tprintf("\nvJoy Device %d capabilities\n", iInterface);
_tprintf("Numner of buttons\t\t%d\n", nButtons);
_tprintf("Axis X\t\t%s\n", AxisX?"Yes":"No");
_tprintf("Axis Y\t\t%s\n", AxisX?"Yes":"No");
_tprintf("Axis Z\t\t%s\n", AxisX?"Yes":"No");
_tprintf("Axis Rx\t\t%s\n", AxisRX?"Yes":"No");
if (ContinuousPOV)
{
// Make Continuous POV Hat spin
iReport.bHats = (DWORD)(count*70);
iReport.bHatsEx1 = (DWORD)(count*70)+3000;
iReport.bHatsEx2 = (DWORD)(count*70)+5000;
iReport.bHatsEx3 = 15000 - (DWORD)(count*70);
if ((count*70) > 36000)
{
iReport.bHats = -1; // Neutral state
iReport.bHatsEx1 = -1; // Neutral state
iReport.bHatsEx2 = -1; // Neutral state
iReport.bHatsEx3 = -1; // Neutral state
};
}
else
{
// Make 5-position POV Hat spin
unsigned char pov[4];
pov[0] = ((count/20) + 0)%4;
pov[1] = ((count/20) + 1)%4;
pov[2] = ((count/20) + 2)%4;
pov[3] = ((count/20) + 3)%4;
If the structure changes in the future then the code will have to change too.
Robust:
// Reset this device to default values
ResetVJD(iInterface);
Sleep(20);
value+=10;
}
This code is readable and does not relay on any specific structure. However, the driver is updated with every
SetAxis() and every SetBtn().
[2.0.5]
VJOYINTERFACE_API BOOL __cdecl DriverMatch(WORD * DllVer, WORD * DrvVer);
Returns TRUE if vJoyInterface.dll file version and vJoy Driver version are identical. Otherwise returns FALSE.
Optional (You may pass NULL):
Output parameter DllVer: If a pointer to WORD is passed then the value of the DLL file version will be written to this
parameter (e.g. 0x205).
Output parameter DrvVer: If a pointer to WORD is passed then the value of the Driver version will be written to this
parameter (e.g. 0x205).
When you deploy your feeder, don't forget to supply the user with file vJoyInterface.dll of the correct bitness.
Location of Feeder
You may locate your feeder anywhere you like provided that file vJoyInterface.dll is on the feeder's search path.
Here are a few points that may help you decide where to deploy your feeder:
1. If you choose to link to file vJoyInterface.dll provided by this SDK you risk to use a non-optimal library. If
the user upgrades vJoy, you risk linking to an outdated library.
2. If you choose to link to file vJoyInterface.dll provided by vJoy Driver installation you need to locate the
library file while installing your feeder.
Location of vJoyInterface.dll
[2.0.5]
vJoy folders are pointed at by registry Entries located under key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{8E31F76F-74C3-47F1-9550-E041EEDC5FBB}_is1
Note that on 64-bit machine you are capable of developing both 32-bit and 64-bit feeders.
You can assume that DLL files are located in sub-folders x64 and x32 under vJoy root folder.
Logging [2.0.5]
Logging of vJoyInterface.dll activity into a log file is an option.
Use this feature for debugging purposes only. It accumulates data into the log file and generally slows down the
system.
This feature is intended both for helping you develop your feeder and to collect data at the user's location – provided
the user is willing to trigger logging for you. By default, logging state is OFF.
Start/Stop Logging.
To start logging, there are one or two system environment variables that have to be changed before the feeder (Or any
other application calling vJoyInterface.dll) is started.
• VJOYINTERFACELOGLEVEL:
Any positive value will trigger logging.
Set to 0 to stop logging.
• VJOYINTERFACELOGFILE (Optional):
If set, this is the full path to the log file.
Default Path: %TEMP%\vJoyInterface.log
Example:
Notes:
• This session of vJoyFeeder will log into the given file.
• If the file exists, it will append the new data to the existing file.
• To stop logging, kill vJoyFeeder and then close this window.
Limitations:
• Logging begins on the application's first call to function AcquireVJD()
• If VJOYINTERFACELOGFILE is not defined, all applications that call AcquireVJD() will write to the same
default output file.
Log File
The log file contains information about vJoyInterface.dll values, states and functions. It is mainly useful in
conjunction with the code.
Here is a snippet of a log file:
[04988]Info: GetHandleByIndex(index=3) - Starting
[04988]Info: GetHandleByIndex(index=3) - Exit OK (Handle to \\?\hid#hidclass&col01#1&2d595ca7&db&0000#{4d1e55b2-
f16f-11cf-88cb-001111000030})
[03088]Process:"D:\WinDDK\vJoy-2.0.5\apps\vJoyFeeder\x64\Release\vJoyFeeder.exe"
You can see the end of one process (Process ids are in brackets) and the beginning of a second process. The first line
referring the second project is highlighted, and it indicates the command this process is carrying out.
Every line in the log file starts with the process id and followed by an error level string such as Info and a column.
The next string is usually the name of the function (e.g. isRawDevice) and its significant parameters.
For full understanding of the printout you should refer to the source file.