I am trying to write a simple library to work with long integers. Using of special optimization based on intrinsic method _addcarry_u64 of 64-bit compiler get an unexpected result in the following code if used optimization. Debug version working as expected.
inline uint64_t addc(const uint64_t& value1, const uint64_t& value2, uint64_t& carry) noexcept
{
uint64_t result;
carry = _addcarry_u64(static_cast<uint8_t>(carry), value1, value2, &result);
return result;
}
template<typename native_t = uintmax_t>
class long_t
{
public:
static_assert(std::is_unsigned_v<native_t>, "unsigned long integer native type must be unsigned");
using native_array_t = std::array<native_t, 2>;
long_t() noexcept;
constexpr long_t(const long_t& that) noexcept = default;
constexpr long_t(long_t&& that) noexcept = default;
constexpr long_t(native_array_t digits) noexcept;
constexpr long_t(const native_t& value) noexcept;
template<typename type_t, std::enable_if_t<std::is_unsigned_v<type_t>, int> = 0>
constexpr long_t(type_t value) noexcept;
template<typename type_t, std::enable_if_t<std::is_signed_v<type_t>, int> = 0>
constexpr long_t(type_t value) noexcept;
constexpr bool operator==(const long_t& that) const noexcept;
constexpr long_t& operator+=(const long_t& that) noexcept;
constexpr long_t operator+(const long_t& that) const noexcept;
native_array_t digits;
};
template<typename native_t>
inline long_t<native_t>::long_t() noexcept
{
}
template<typename native_t>
inline constexpr long_t<native_t>::long_t(native_array_t digits) noexcept
: digits(digits)
{
}
template<typename native_t>
inline constexpr long_t<native_t>::long_t(const native_t& value) noexcept
: long_t({ value, 0})
{
}
template<typename native_t>
template<typename type_t, std::enable_if_t<std::is_unsigned_v<type_t>, int>>
inline constexpr long_t<native_t>::long_t(type_t value) noexcept
: long_t({ native_t(value), 0 })
{
}
template<typename native_t>
template<typename type_t, std::enable_if_t<std::is_signed_v<type_t>, int>>
inline constexpr long_t<native_t>::long_t(type_t value) noexcept
: long_t({ static_cast<native_t>(value), (value >= 0 ? 0 : native_t(~0)) })
{
}
template<typename native_t>
inline constexpr bool long_t<native_t>::operator==(const long_t& that) const noexcept
{
if (digits[1] != that.digits[1])
return false;
if (digits[0] != that.digits[0])
return false;
return true;
}
template<typename native_t>
inline constexpr long_t<native_t>& long_t<native_t>::operator+=(const long_t& that) noexcept
{
native_t carry = 0;
digits[0] = addc(digits[0], that.digits[0], carry);
digits[1] = addc(digits[1], that.digits[1], carry);
return *this;
}
template<typename native_t>
inline constexpr long_t<native_t> long_t<native_t>::operator+(const long_t& that) const noexcept
{
return long_t(*this) += that;
}
int main()
{
const bool result = long_t<uintmax_t>(0) + -1 == -1;
std::cout << "result:" << result;
return 0;
}
Output is:
result:0
Replacing of optimized addc version caused to predictable result:
template<typename type_t, std::enable_if_t<std::is_unsigned_v<type_t>, int>>
inline constexpr type_t addc(const type_t& value1, const type_t& value2, type_t& carry) noexcept
{
const type_t tmp = value2 + carry;
const type_t result = value1 + tmp;
carry = (tmp < value2) || (result < value1);
return result;
}
Output is:
result:1
The problem appears on Microsoft Visual Studio 2017 version 15.9.23 on 64-bit C++ compiler in full optimization mode.
Related
I need an std::allocator<> compliant allocator with page-aligned allocation and preferrably no memory-pooling for very large allocations. Another requirement is that the allocator should have a non-standard reset()-method to reset a row of pages that the pages become discardable by the kernel if you have a row of trivial data types.
I wrote such an allocator which I post here below completely since I think others could use the allocator also if they also have this certain allocation constraints.
#pragma once
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <unistd.h>
#include <sys/mman.h>
#else
#error platform not supported
#endif
#include <cstddef>
#include <type_traits>
#include <memory>
#include <utility>
#include <atomic>
#include <cassert>
#include <new>
#if !defined(NDEBUG)
#include <bit>
#endif
#include <utility>
template <typename T>
struct virtual_allocator
{
using allocator_type = virtual_allocator;
using value_type = T;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using propagate_on_container_move_assignment = std::false_type;
constexpr virtual_allocator() noexcept {}
constexpr virtual_allocator( virtual_allocator const & ) noexcept {}
static value_type *allocate( std::size_t n );
static void deallocate( value_type *p, std::size_t n ) noexcept;
static void reset( void *p, std::size_t n )
requires (sizeof(T) == std::bit_floor( sizeof(T) )) && std::is_trivial_v<T>;
static std::size_t get_page_size();
#if defined(__cpp_lib_allocate_at_least)
static std::allocation_result<value_type *> allocate_at_least( std::size_t n );
#endif
private:
using alloc_ret_t = std::pair<value_type *, std::size_t>;
static alloc_ret_t allocateAtLeast( std::size_t n );
static std::size_t getPageSize();
};
template <typename T>
typename virtual_allocator<T>::value_type *virtual_allocator<T>::allocate( std::size_t n )
{
return allocateAtLeast( n ).first;
}
template <typename T>
void virtual_allocator<T>::deallocate( value_type *p, std::size_t n ) noexcept
{
std::size_t pageSize = getPageSize();
assert(n * pageSize / pageSize == n);
n = n * pageSize + pageSize - 1 & -(ptrdiff_t)pageSize;
#if defined(_WIN32)
bool succ = (bool)VirtualFree( p, 0, MEM_RELEASE );
#elif defined(__unix__)
bool succ = !munmap( p, n );
#endif
assert(succ);
}
#if defined(__cpp_lib_allocate_at_least)
template <typename T>
std::allocation_result<typename virtual_allocator<T>::value_type *> virtual_allocator<T>::allocate_at_least( std::size_t n )
{
auto ret = allocateAtLeast( n );
return std::allocation_result<value_type *>( ret.first, ret.second );
}
#endif
template <typename T>
typename virtual_allocator<T>::alloc_ret_t virtual_allocator<T>::allocateAtLeast( std::size_t n )
{
using namespace std;
if( n * sizeof(value_type) / sizeof(value_type) != n )
throw bad_alloc();
size_t pageSize = getPageSize();
n = n * sizeof(value_type) + pageSize - 1 & -(ptrdiff_t)pageSize;
#if defined(_WIN32)
value_type *p = (value_type *)VirtualAlloc( nullptr, n, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE );
#elif defined(__unix__)
value_type *p = (value_type *)mmap( nullptr, n, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0 );
#endif
if( !p ) [[unlikely]]
throw bad_alloc();
return alloc_ret_t( p, n / sizeof(value_type) );
}
template <typename T>
void virtual_allocator<T>::reset( void *p, std::size_t n )
requires (sizeof(T) == std::bit_floor( sizeof(T) )) && std::is_trivial_v<T>
{
using namespace std;
if( ((size_t)p | n) & getPageSize() - 1 || n * sizeof(value_type) / sizeof(value_type) != n ) [[unlikely]]
throw bad_alloc();
#if defined(_WIN32)
bool succ = (bool)VirtualAlloc( p, n, MEM_RESET, PAGE_READWRITE );
#elif defined(__unix__)
bool succ = !madvise( p, n, MADV_DONTNEED );
#endif
assert(succ);
}
template <typename T>
inline
std::size_t virtual_allocator<T>::get_page_size()
{
return getPageSize();
}
template <typename T>
inline
std::size_t virtual_allocator<T>::getPageSize()
{
using namespace std;
static atomic<size_t> aPageSize( 0 );
size_t pageSize = aPageSize.load( memory_order_relaxed );
if( !pageSize ) [[unlikely]]
{
#if defined(_WIN32)
SYSTEM_INFO si;
GetSystemInfo( &si );
pageSize = si.dwPageSize;
#elif defined(__unix__)
pageSize = sysconf( _SC_PAGESIZE );
#endif
assert(pageSize && pageSize == bit_floor( pageSize ));
aPageSize.store( pageSize, memory_order_relaxed );
}
return pageSize;
}
The testing code compiles fine with g++ 11.1.0 and clang++ 13 under Linux. Under Windows it compiles if you have a "Release" compile but not in "Debug" mode. I get some weird errors for which I don't have any clue what they're abut.
Severity Code Description Project File Line Suppression State
Error C2440 'static_cast': cannot convert from 'virtual_allocator<array_t>' to 'virtual_allocator<_Newfirst>' virtual_allocator C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\vector 595
Error C2530 '_Alproxy': references must be initialized virtual_allocator C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\vector 595
Error C3536 '_Alproxy': cannot be used before it is initialized virtual_allocator C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\vector 596
Error C2672 '_Delete_plain_internal': no matching overloaded function found virtual_allocator C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\vector 596
Error C2893 Failed to specialize function template 'void std::_Delete_plain_internal(_Alloc &,_Alloc::value_type *const ) noexcept' virtual_allocator C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\vector 596
Although I think the code would be helpful for other C++-developers I don't post this with any C++-tags. That's while if others search such an allcator they'll find it by googling anyway and my question is only related to Visual C++.
Yeah, Igor got it ! It was the missing templated constructor.
template<typename T2>
constexpr virtual_allocator( virtual_allocator<T2> const & ) noexcept {}
I'm trying to create a map like
std::map<std::map <std::string,std::string>, MyDataTyp*>,
therefore I put
std::map<std::string, std::string>
in a separate class like:
class TagList {
public:
std::map<std::string, std::string> _map;
TagList() {}
~TagList() {}
void addTag(const std::string tag, const std::string value) { if (tag != "") _map[tag] = value; }
std::string getValue(const std::string tag) {
std::map<std::string, std::string>::iterator it = _map.find(tag);
if (it == _map.end()) return ("");
else return (it->second);
}
};
inline bool operator< (const TagList &a, const TagList &b) {
std::map<std::string, std::string>::iterator it ;
for (it = a._map.begin(); it != a._map.end(); it++) {
std::string myVal1 = it->second;
std::string myVal2 = b._map.find(it->first);
if (myVal2 == "") return false;
if (strcmp(myVal1.c_str(),myVal2.c_str()) > 0) return true;
}
return false;
}
Hope someone can explain me the error message
Error 4 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Tree_const_iterator<_Mytree>' (or there is no acceptable conversion) (...)
...and what is the reason for my confision....
Sorry, my fault...
found the answer by myself:
inline bool operator< (const TagList &a, const TagList &b) {
std::map<std::string, std::string>::const_iterator it ;
std::map<std::string, std::string>::const_iterator it2 ;
for (it = a._map.begin(); it != a._map.end(); it++) {
std::string myVal1 = it->second;
it2 = b._map.find(it->first);
std::string myVal2 = it2->second;
if (myVal2 == "") return false;
if (strcmp(myVal1.c_str(),myVal2.c_str()) > 0) return true;
}
return false;
}
it wasn't const
Thx
George
As normal C++ execl works fine (compiling with g++ ok.cc -o ok.elf)
#include <unistd.h>
int main(){
execl("/usr/bin/python", "/usr/bin/python", nullptr);
}
But crashes, when works as node.js C++ addon
#include <node.h>
#include <unistd.h>
namespace bug{
void wtf(const v8::FunctionCallbackInfo<v8::Value>& args){
execl("/usr/bin/python", "/usr/bin/python", nullptr);
}
void init(v8::Local<v8::Object> exports){
NODE_SET_METHOD(exports, "wtf", bug::wtf);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
}
node.js v8.9.1
node-gyp v3.6.2
gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)
Node doesn't support all posix syscall.
See this thread
A way to call execl, execle, execlp, execv, execvP or execvp from Node.js
The crash is expected as you are using something that is not available to you. As discussed in the above thread you need to either create your own exec
index.cc
#include <nan.h>
#include <fcntl.h>
#include <unistd.h>
int doNotCloseStreamsOnExit(int desc) {
int flags = fcntl(desc, F_GETFD, 0);
if (flags < 0) return flags;
flags &= ~FD_CLOEXEC; //clear FD_CLOEXEC bit
return fcntl(desc, F_SETFD, flags);
}
void copyArray(char* dest[], unsigned int offset, v8::Local<v8::Array> src) {
unsigned int length = src->Length();
for (unsigned int i = 0; i < length; i++) {
v8::String::Utf8Value arrayElem(Nan::Get(src, i).ToLocalChecked()->ToString());
std::string arrayElemStr (*arrayElem);
char* tmp = new char[arrayElemStr.length() +1];
strcpy(tmp, arrayElemStr.c_str());
dest[i + offset] = tmp;
}
}
void setEnv(v8::Local<v8::Array> src) {
unsigned int length = src->Length();
v8::Local<v8::String> keyProp = Nan::New<v8::String>("key").ToLocalChecked();
v8::Local<v8::String> valueProp = Nan::New<v8::String>("value").ToLocalChecked();
for (unsigned int i = 0; i < length; i++) {
v8::Local<v8::Object> obj = Nan::Get(src, i).ToLocalChecked()->ToObject();
v8::String::Utf8Value objKey(Nan::Get(obj, keyProp).ToLocalChecked()->ToString());
v8::String::Utf8Value objValue(Nan::Get(obj, valueProp).ToLocalChecked()->ToString());
std::string objKeyStr (*objKey);
char *key = const_cast<char*> ( objKeyStr.c_str() );
std::string objValueStr (*objValue);
char *value = const_cast<char*> ( objValueStr.c_str() );
setenv(key, value, 1);
}
}
void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() < 3) {
return;
}
if (!info[0]->IsString()) {
return;
}
// get command
v8::String::Utf8Value val(info[0]->ToString());
std::string str (*val);
char *command = const_cast<char*> ( str.c_str() );
// set env on the current process
v8::Local<v8::Array> envArr = v8::Local<v8::Array>::Cast(info[1]);
setEnv(envArr);
// build args: command, ...args, NULL
v8::Local<v8::Array> argsArr = v8::Local<v8::Array>::Cast(info[2]);
char* args[argsArr->Length() + 2];
args[0] = command;
copyArray(args, 1, argsArr);
args[argsArr->Length() + 1] = NULL;
// fix stream flags
doNotCloseStreamsOnExit(0); //stdin
doNotCloseStreamsOnExit(1); //stdout
doNotCloseStreamsOnExit(2); //stderr
execvp(command, args);
}
void Init(v8::Local<v8::Object> exports) {
exports->Set(Nan::New("exec").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(Method)->GetFunction());
}
NODE_MODULE(exec, Init)
index.js
'use strict';
var addon = require('bindings')('addon');
var path = require('path');
var fs = require('fs');
module.exports = function(cmd, env, args) {
if (!cmd) {
throw new Error('Command is required');
}
var envArr = Object.keys(env || {}).map(key => {
return {
key,
value: env[key],
};
});
addon.exec(cmd, envArr, args || []);
};
PS: Code posted from https://github.com/OrKoN/native-exec, in case link goes inactive in future
Also another thing that you shouldn't try to do is execute something which needs to get the TTY, you will add a lot of complexity in that case. So running python will need to take control of your TTY.
I have code like this, that compiles fines in all compiler I've tested except VS2010.
I'm trying not to use C++11 specific features here, so it can still compile on outdated compiler like gcc 4.1.
#include <iostream>
using namespace std;
// Simplified variant class
struct Var
{
template <class T>
Var(T t) {}
Var(void) {}
};
// Simplified argument array class
struct FuncArgs
{
};
/** Make a wrapper around the given function */
template <int line, typename Ret, Ret Func()>
Var WrapFuncT(const FuncArgs & args)
{
Var ret;
ret = Func(); return ret;
}
/** Make a wrapper around the given function */
template <int line, void Func()>
Var WrapFuncT(const FuncArgs & args)
{
Var ret;
Func(); return ret;
}
// Unary
template <int line, typename Ret, typename Arg1, Ret Func(Arg1)>
Var WrapFuncT(const FuncArgs & args)
{
Var ret; Arg1 arg;
ret = Func(arg);
return ret;
}
template <int line, typename Arg1, void Func(Arg1)>
Var WrapFuncT(const FuncArgs & args)
{
Var ret; Arg1 arg;
Func(arg);
return ret;
}
// Binary
template <int line, typename Ret, typename Arg1, typename Arg2, Ret Func(Arg1, Arg2)>
Var WrapFuncT(const FuncArgs & args)
{
Var ret; Arg1 arg1; Arg2 arg2;
ret = Func(arg1, arg2);
return ret;
}
template <int line, typename Arg1, typename Arg2, void Func(Arg1, Arg2)>
Var WrapFuncT(const FuncArgs & args)
{
Var ret; Arg1 arg1; Arg2 arg2;
Func(arg1, arg2);
return ret;
}
#define WrapFunc(X, Y, ...) &WrapFuncT<__LINE__, X, Y, ## __VA_ARGS__ >
int testFunc()
{
return 42;
}
void testFunc2(int value)
{
cout<<value<<endl;
}
typedef Var (*NamedFunc)(const FuncArgs &);
int main()
{
NamedFunc a, b;
a = WrapFunc(int, testFunc);
b = WrapFunc(int, testFunc2);
}
Visual studio 2010 compiler chokes on this with error:
In line 'a = WrapFunc(int, testFunc);' : error C2440: 'specialization' : cannot convert from 'int (__cdecl *)(void)' to 'void (__cdecl *const )(int)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2973: 'Type::WrapFuncT' : invalid template argument 'int (__cdecl *)(void)'
In line 'template <int line, typename Arg1, void Func(Arg1)>' : see declaration of 'Type::WrapFuncT'
Seems like VS2010 does not find the former definition template < int line, typename Ret, Ret Func(void) > with Ret = int for int testFunc(void) function, and instead tries and errors on the template < int line, typename Arg1, void Func(Arg1) >.
If I comment the later, then it compiles fine, so it is able to find the former overload.
I've tried to solve this in numerous way, none worked, as I need to "capture" a pointer to function in a same signature function Var (*) (const FuncArgs &)
You may try a generic template function and using specialization with structure, something like:
namespace detail
{
// class to specialize for each function type
template <int line, typename F, F f> struct helper_wrapper;
// partial specialization
template <int line, typename Ret, Ret (&Func)()>
struct helper_wrapper<line, Ret (&)(void), Func>
{
Var operator()(const FuncArgs&) const
{
Var ret;
ret = Func();
return ret;
}
};
// partial specialization
template <int line, void (&Func)()>
struct helper_wrapper<line, void (&)(), Func>
{
Var operator()(const FuncArgs&) const
{
Var ret;
Func();
return ret;
}
};
// partial specialization
template <int line, typename Ret, typename Arg1, Ret (&Func)(Arg1)>
struct helper_wrapper<line, Ret (&)(Arg1), Func>
{
Var operator()(const FuncArgs&) const
{
Var ret;
Arg1 arg;
ret = Func(arg);
return ret;
}
};
// partial specialization
template <int line, typename Arg1, void (&Func)(Arg1)>
struct helper_wrapper<line, void (&)(Arg1), Func>
{
Var operator()(const FuncArgs&) const
{
Var ret;
Arg1 arg;
Func(arg);
return ret;
}
};
// other partial specialization omitted.
}
// The general function
template <int line, typename F, F f>
Var WrapFuncT(const FuncArgs& arg) { return detail::helper_wrapper<line, F, f>()(arg); }
// The helper macro
#define WrapFunc(X, Y) &WrapFuncT<__LINE__, X, Y>
And then call it that way:
a = WrapFunc(int(&)(), testFunc);
b = WrapFunc(void(&)(int), testFunc2);
This is the Oculus street view project.....just i am trying to understand and run but i could not do it......please help me
// dllmain.cpp : Defines the entry point for the DLL application.
include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
include "stdafx.h"
#include "libovrwrapper.h"
#include <OVR.h>
using namespace OVR;
// Ptr<> AddRef'ed, AutoCleaned
bool bInited = false;
Ptr<DeviceManager> pManager;
Ptr<HMDDevice> pHMD;
Ptr<SensorDevice> pSensor;
SensorFusion pSensorFusion;
LIBOVRWRAPPER_API int OVR_Init()
{
bInited = false;
System::Init(Log::ConfigureDefaultLog(LogMask_Regular));
if (System::IsInitialized())
{
int stage = -1;
while (++stage > -1 && !bInited)
{
switch (stage)
{
case 0:
pManager = *DeviceManager::Create();
if (pManager == NULL)
return bInited;
break;
case 1:
pHMD = *pManager->EnumerateDevices<HMDDevice>().CreateDevice();
if (pHMD == NULL)
return bInited;
break;
case 2:
pSensor = *pHMD->GetSensor();
if (pSensor == NULL)
return bInited;
break;
default:
bInited = true;
break;
};
}
}
pSensorFusion.AttachToSensor(pSensor);
return (bInited?1:0);
}
LIBOVRWRAPPER_API void OVR_Exit()
{
if (bInited)
{
System::Destroy();
}
}
LIBOVRWRAPPER_API int OVR_QueryHMD(OVR_HMDInfo* refHmdInfo)
{
if (!bInited)
{
return 0;
}
HMDInfo src;
if (pHMD->GetDeviceInfo(&src))
{
refHmdInfo->HResolution = src.HResolution;
refHmdInfo->VResolution = src.VResolution;
refHmdInfo->HScreenSize = src.HScreenSize;
refHmdInfo->VScreenSize = src.VScreenSize;
refHmdInfo->VScreenCenter = src.VScreenCenter;
refHmdInfo->EyeToScreenDistance = src.EyeToScreenDistance;
refHmdInfo->LensSeparationDistance = src.LensSeparationDistance;
refHmdInfo->InterpupillaryDistance = src.InterpupillaryDistance;
refHmdInfo->DistortionK[0] = src.DistortionK[0];
refHmdInfo->DistortionK[1] = src.DistortionK[1];
refHmdInfo->DistortionK[2] = src.DistortionK[2];
refHmdInfo->DistortionK[3] = src.DistortionK[3];
refHmdInfo->DesktopX = src.DesktopX;
refHmdInfo->DesktopY = src.DesktopY;
memcpy(refHmdInfo->DisplayDeviceName, src.DisplayDeviceName, sizeof(refHmdInfo->DisplayDeviceName));
}
return 1;
}
LIBOVRWRAPPER_API int OVR_PeekYPL(float* yaw, float* pitch, float* roll)
{
if (!bInited)
{
return 0;
}
Quatf hmdOrient = pSensorFusion.GetOrientation();
hmdOrient.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(yaw, pitch, roll);
return 1;
}
LIBOVRWRAPPER_API int OVR_Peek(float* w, float* x, float* y,float * z)
{
if (!bInited)
{
return 0;
}
Quatf hmdOrient = pSensorFusion.GetOrientation();
*w = hmdOrient.w;
*x = hmdOrient.x;
*y = hmdOrient.y;
*z = hmdOrient.z;
//hmdOrient.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(yaw, pitch, roll);
return 1;
}
#ifdef LIBOVRWRAPPER_EXPORTS
#if defined __cplusplus
#define LIBOVRWRAPPER_API extern "C" __declspec(dllexport)
#else
#define LIBOVRWRAPPER_API __declspec(dllexport)
#endif
#else
#if defined __cplusplus
#define LIBOVRWRAPPER_API extern "C" __declspec(dllimport)
#else
#define LIBOVRWRAPPER_API __declspec(dllimport)
#endif
#endif
struct OVR_HMDInfo
{
unsigned HResolution;
unsigned VResolution;
float HScreenSize;
float VScreenSize;
float VScreenCenter;
float EyeToScreenDistance;
float LensSeparationDistance;
float InterpupillaryDistance;
float DistortionK[4];
int DesktopX;
int DesktopY;
char DisplayDeviceName[32];
};
LIBOVRWRAPPER_API int OVR_Init();
LIBOVRWRAPPER_API void OVR_Exit();
LIBOVRWRAPPER_API int OVR_QueryHMD(struct OVR_HMDInfo* refHmdInfo);
LIBOVRWRAPPER_API int OVR_Peek(float* w, float* x, float* y,float * z);
LIBOVRWRAPPER_API int OVR_PeekYPL(float* yaw, float* pitch, float* roll);
Your question is very difficult to understand, as it doesn't have any real details about what you've tried, what isn't working, etc.
It looks like you are trying to "run" a DLL, which isn't really possible. A DLL has to be loaded by another application. So you would have an executable of some kind that would load this DLL, and call into its OVR_Init and OVR_Exit functions.