Is there any example of c #
Is there any example of C# to reference the openvr dll ? or some other methods to resovle
There are multiple ways of doing so, but personally I use an IDE and do it this way:
- create separate project
OpenVRApiModule(DLL type), - enter that project root directory,
- execute shell command
git clone https://github.com/ValveSoftware/openvr.git, - add existing file
{project root}/openvr/headers/openvr_api.csto the project, - add existing file
{project root}/openvr/bin/win32/openvr_api.dllto the project (you can use other builds if needed), - set property in the project for
openvr_api.dllto always copy to output directory, - add
OpenVRApiModuleproject the workspace where you want to use it (if you didn't do it initially). - add
OpenVRApiModuleproject as a reference to projects that use OpenVR.
As a result you will get all OpenVR API available with type hinting in your IDE. When you will build your project OpenVRApiModule will also be built as a dependency into OpenVRApiModule.dll and copied along with openvr_api.dll to your output directory. As a result you should get your program working right away without any need of post-build steps.
It also makes easy to update used api to newest version. Just use shell command git pull from within {project root}/openvr directory when needed. All projects will use the newer version right away.
Otherwise you could do similarily and clone OpenVR repository into an already existing project and add openvr_api.cs and openvr_api.dll the same way as I add them to OpenVRApiModule. This will give you same result except that you will have two extra files in your project tree and when you will want to update OpenVR API to a newer version you will have to do it in all your projects.
Thank you very much, it works.
Thanks. I copied this here as well: https://steamcommunity.com/app/358720/discussions/0/142260895142733091/
Update
Had to do a couple things to get everything working.
- Create a new Project and choose "Class Library (.NET Framework)" type Visual C#
- Delete the
Class1.csfile, because it is unneeded. - Move the files as instructed in steps 4 and 5.
Common Errors
- "The OutputPath property is not set for this project"
- Fix: https://stackoverflow.com/a/31703751/1762224
- "Source file settings.designer.cs could not be found"
- Fix: https://stackoverflow.com/a/25569975/1762224
When I try these instructions, it works and compiles but when I run the application it says it couldn't find openvr_api.dll (I made sure to copy to output directory). I also tried putting openvr_api.dll in the project folder but it says it couldn't find assembly manifest. Also when I view the compiled assembly in a dependency viewer openvr_api is not found.
FYI: for error Unable to load DLL 'openvr_api' or one of its dependencies: File not found (maybe #1630?)
I noticed the openvr_api.dll has to be at the built root and not in a subfolder (even when debugging the app in Visual Studio).
Copying openvr_api.dll into a subfolder in my project resulted in that subfolder also being created in the build output dir.
After configuring Visual Studio to copy the dll file to the output root without creating a subfolder, it worked just fine.