Skip to content

Commit e10fa4d

Browse files
committed
Updated C++ sample
1 parent d584a12 commit e10fa4d

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

С++/GetData/GetData/GetData.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "stdafx.h"
22
#include <Windows.h>
3+
#include <atlbase.h>
34

45
typedef struct _HMDData
56
{
@@ -18,19 +19,39 @@ typedef DWORD(_stdcall *_GetHMDData)(__out THMD* myHMD);
1819

1920
int main()
2021
{
21-
//Path to "TOVR.dll" on Registry - "HKEY_CURRENT_USER\Software\TrueOpenVR" parameter "Library"
22-
HMODULE hDll = LoadLibrary(L"TOVR.dll");
22+
//Read main library path from registry
23+
CRegKey key;
24+
TCHAR libPath[MAX_PATH];
25+
26+
LONG status = key.Open(HKEY_CURRENT_USER, _T("Software\\TrueOpenVR"));
27+
if (status == ERROR_SUCCESS)
28+
{
29+
ULONG libPathSize = sizeof(libPath);
30+
status = key.QueryStringValue(_T("Library"), libPath, &libPathSize);
31+
32+
if (status != ERROR_SUCCESS)
33+
{
34+
printf("Error read library path\n");
35+
return 1;
36+
}
37+
}
38+
else
39+
{
40+
printf("Error open registry path TrueOpenVR");
41+
return 1;
42+
}
43+
key.Close();
44+
45+
//Load main library
46+
HMODULE hDll = LoadLibrary(libPath);
2347
if (hDll == NULL) {
2448
printf("ERROR: unable to load DLL\n");
2549
return 1;
2650
}
2751

2852
THMD myHMD;
29-
3053
ZeroMemory(&myHMD, sizeof(THMD));
31-
3254
_GetHMDData GetHMDData;
33-
3455
GetHMDData = (_GetHMDData)GetProcAddress(hDll, "GetHMDData");
3556

3657
if (GetHMDData == NULL) {
@@ -39,17 +60,15 @@ int main()
3960
}
4061

4162
DWORD iResult = GetHMDData(&myHMD);
42-
4363
Sleep(300);
44-
4564
GetHMDData(&myHMD);
4665

4766
printf("Result = %d\n", iResult);
48-
4967
printf("X = %f\nY = %f\nZ = %f\nYaw = %f\nPitch = %f\nRoll = %f\n\n", myHMD.X, myHMD.Y, myHMD.Z, myHMD.Yaw, myHMD.Pitch, myHMD.Roll);
5068

51-
system("pause");
5269
FreeLibrary(hDll);
5370
hDll = nullptr;
71+
72+
system("pause");
5473
return 0;
5574
}

С++/GetData/GetData/GetData.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ConfigurationType>Application</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
3232
<PlatformToolset>v141</PlatformToolset>
33-
<CharacterSet>Unicode</CharacterSet>
33+
<CharacterSet>MultiByte</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>Application</ConfigurationType>

0 commit comments

Comments
 (0)