Cannot access filesystem in CMake UPW Project - c++

I built an application that uses OpenXR with DirectX to display a simple scene in VR. As I'm tasked with implementing this in an already existing project, it's built using CMake, which works perfectly fine with Visual Studio 2019.
The application can run without any issues on the Windows MR Portal, as well as on the Oculus Rift S with the Oculus OpenXR runtime.
Now the next step is to get it running on the hololens. As I need an UWP project to do this, I created a .sln for the application I want to run on the hololens with CMake as follows:
cmake -G "Visual Studio 16 2019" -A x64 ..\.. -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0
With this, I can open the project and compile it as UWP, works without any issues. Now, when I want to run the application to debug it, I get the following error:
Exception thrown at 0x00007FFD3CC83E49 in openxr_test_app.exe: Microsoft C++ exception: std::filesystem::filesystem_error at memory location 0x00000046791CCF50.
Error [GENERAL | | OpenXR-Loader] : Unknown failure: canonical: Access denied: "C:\WINDOWS\system32\MixedRealityRuntime.json"
After some googling, I found out that I might need to add the relevant capability to the Package.appxmanifest, so I added
<rescap:Capability Name="broadFileSystemAccess"/>
as well as
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
and
IgnorableNamespaces="uap mp rescap"
to my Package.appxmanifest and enabled filesystem access for my application in the windows settings panel.
However, I still get the error above, I also tried to access other files on my PC (as I thought maybe system32 is a bit more restricted), but with no success.
I'm especially confused, because the OpenXR sample app from Microsoft works without any issues, and they did not declare the broadFileSystemAccess capability.
Are there any other ways to allow file access, or am I just missing something that I need to enable?

So as a quick follow-up, if anyone runs into the same issue: The problem here was a bug in the OpenXR loader that was introduced in version 1.0.10 of OpenXR.
Updating to OpenXR 1.0.11 solved the issue of the loader not being able to access the MixedRealityRuntime.json file.

Related

DLL not found in redistributable (biddll.dll)

I’m having difficulty getting the sample code for tws api running. I’ve successfully run it on a borrowed laptop but the same version fails on my own windows 10 laptop. When running on Release mode in Win32, I get the popups
The code execution cannot proceed because biddll.dll was not found. Reinstalling the program may fix this problem. and The procedure entry point ?cancelOrder#EClient##QAEXJ#Z could not be located in the >dynamic link library C:\Eclipse-workspace\TWS >API\samples\Cpp\TestCppClient\ReleaseTestCppClient.exe.
I’ve read through several questions similar to this. I’ve tried installing the Visual C++ Redistributable for Visual Studio 2022 for both x86 and x64 from here: https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170. I’ve tried loading biddll.dll from another folder but it gives the message “Module was built without symbols.”. I’ve run “sfc /scannow” for broken files. The issue persists. biddll.dll still seems to not be anywhere in the system files or the API files. The only version is the one I copied from another version of the project.
Thanks for your suggestions. I uninstalled TWS API and reinstalled it. I made sure to build for Release. It sounds like there was a mismatch between some debug libraries and it started pulling them instead. There may have been some unexpected behavior from installing several versions while troubleshooting as well.

Bad image format when running managed C++/CLI assembly in .NET Core 3.1

I was super excited to see that the latest previews of .NET Core 3.1 and Visual Studio 2019 add support for managed C++/CLI projects, as such a project is the only think keeping a particular project on .NET Framework.
So, I installed Visual Studio Preview 16.4.0 Preview 4, along with the "C++/CLI support for v142..." options, and as expected I see the new C++ CLR templates and have .NET Core 3.1 preview 2 installed
I created a new project using the "CLR Class Library (.NET Core)" template, copied the files an old managed C++/CLI project, tweaked a little, and the assembly built - great!
However, when I try to use the assembly in a .NET Core 3.1, I get this fatal exception:
Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'MyAssembly, Version=2019.0.1.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
File name: 'MyAssembly, Version=2019.0.1.0, Culture=neutral, PublicKeyToken=null'
at TestApp.Program.Main(String[] args)
Both the managed assembly and test app target X64. Any ideas what could be the problem?
Someone from Microsoft provided the solution over on the Github repo.
When the managed C++/CLI project is built, a file ijwhost.dll is placed in the output folder alongside the assembly - this file needs to be deployed with the app that uses the assembly.
After putting ijwhost.dll in the same folder as the app, it worked as expected.
As an aside, the old C++/CLI project that I built against .NET Core 3.1 preview is actually quite complex - I'm very pleasantly surprised that it basically "just worked"!
Hopefully a better error message will be used in future!
I am using .net 5.0 as the CLI runtime. I finally found that the problem I have is missing native dependency DLLs.
For native applications, there will be an error prompt telling you which DLL is missing. While in .net core C++/CLI, they only give you a BadImageFormatException.
My solution is, create a pure native console project, paste the code that will cause BadImageFormatException, run it and see which DLL is missing then add it back to C++/CLI project file list.
I just found some unexpected dependencies.
In my case c# Net 5.0 app loads managed C++ dll, which is wrapping around unmanaged C++ dll.I get this error every time i try to run on on machine with no Visual Studio installed. I debugged it with ProcessMonitor and figure out that it can't found VCRUNTIME140D.dll. Found these dlls in my dev PC, copied them (both 32 and 64 bit versions) from my dev machine to customer's one to corresponded folders, and it made the trick. Hope will help somebody. Cheers.

Debugging Qt in visual studio, msvcp140d_app.dll is missing

I'm new to Qt, but have been working with Visual studio for C/C++ development for a few years. Now I'm trying to build a GUI for my project. I installed Qt 5.11.0 and the Qt VS Tools on both my work computer and home PC. At work I can build and run my project with the VS debugger, however on my home system I can build but can't run either with VS debugger or simply launching the app. I tried in release and it runs fine.
The error I'm getting is :
The code execution cannot proceed because VCRUNTIME140D_APP.dll was not found.
I get 4 of these, the first two want VCRUNTIME, the second two want MSVCP140D_APP.dll.
Solutions I've tried so far :
Uninstalled Win SDK and reinstalled
Uninstalled VS2017 and SDK and reinstalled
Searched System32, SysWOW64 and VS install directories - found msvcp140d.dll and vcruntime140d.dll, but no _app.dlls
Does anyone know what these are included with and where to get them? I can't figure out why I have them on my work computer but not at home. I have the same VS updates, same Qt version, and SDK on both systems.
Using :
Visual Studio 2017 v15.7.1
Qt 5.11.0 - msvc2017_64
I suppose I can just copy the .dll's from my work pc and drop them in the appropriate locations on the other, but I'd like to know what they should have been installed with so I can have the same setup on both systems.
Edit:
I also tried changing the platform toolset to VS2015 with Qt versions msvc2015_64 and winrt_x64_msvc2015
I found this post concerning the same missing _app.dll files. There wasn't any answer there, which is why I tried reinstalling the SDK in the hope the missing files were included there.
Edit 2:
I just scanned my entire system at work and it turns out that I don't have the missing .dll there either. That tells me that there is a difference in the project properties or configuration between the two. I use git for source control, and I am currently the only contributor to this project. When I try to build and run just the example from the getting started guide I have the same problem at home with missing _app.dll files, however it works fine at work. I'm totally confused now, and any hints are greatly appreciated.
Solution:
After trying for a couple of hours making new solutions etc. I decided to delete the entire build folder and put fresh copies of all the dependencies into it. My project now runs fine in debugging mode.
I'm fairly certain that when I originally copied the Qt .dll files into it I must have grabbed them from one of the winrt folders rather than the msvc2017_64 folder. To test I replaced the working .dll files with those from the winrt_x64_msvc2017 folder and sure enough the same errors again. So, this was a dumb mistake on my part, but hopefully it'll save someone else a lot of hair-pulling in the future.

Compiling a C++ application on Windows 7, but execute it on Win2003 Server

I have a C++ application (quite complex, multiple projects) in Visual Studio 2008, that produces a single dll. Recently I switched to Windows 7, but had previously been compiling under Windows XP. Suddenly the dll in question cannot be loaded by another application, i.e. on a machine running Windows 2003 Server.
I've been trying various things:
I've installed the VC9.0 redistributable package on the server
Also copied various .dll's from that package to the application folder
The project is of course compiled in release mode
When I run depends.exe on the client machine, I do get the following error:
"Error: The Side-by-Side configuration information for "my_dll.dll" contains errors. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001).
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module."
and the icon for shlwapi.dll has a red overlay icon.
This didn't happen when I was compiling under WinXP, so I'm guessing that there really is no problem with the .dll's on the client machine, but somewhere there is a reference to that particular version of some dll.
Does anyone know what would be the best way to resolve this?
Regards,
Daníel
OK I found it, and it turns out to be the same problem as described here:
vcredist_x86.dll and version 8.0.50727.4053
I had to compare the resources of the old binary with the new one, to notice the difference.

0xc000007b "The application was unable to start correctly" error?

I've written a C++ console application in Visual Studio 2019 and am trying to deploy it to another windows laptop. Both laptops are up-to-date with 64 bit Windows 10, and my target laptop has installed/up-to-date .NET Framework, vc_redist.x64.exe, and DirectX.
In terms of deployment method, I followed this Microsoft walkthrough word for word, with the added step of ensuring that my newly created "setup" project was also targeting x64 platform, since some of the external libraries in my code required x64. The resulting "setup" .exe/.msi pair work as planned on the source laptop - installs and runs with no frills required.
Installation goes fine on the target laptop, but launching the program gives the error mentioned in the title of this post. After a few hours of trying to figure it out, I think I have an idea where the problem is coming from, but first, I'll share what I've tried, which is basically every recommendation found by googling this error code:
clean boot
SFC scan
chkdsk c: /f /r
repairing/fresh installing all of the frameworks mentioned in the first paragraph
running both the application installer and the installed application as administrator
restarting laptop and reinstalling application after all of those changes
What I think is the root of the problem:
In the setup/deployment project in VS, three of the "detected dependencies" (MSVCP140D.dll, ucrtbased.dll, VCRUNTIME140D.dll) have filepaths through …\System32\ rather than the identical dependencies that could be found in …\SysWOW64. The other two detected dependencies are external 64-bit DLLs (which is why I specified my entire project to x64). When I run my application through Dependency Walker, it agrees that the three formerly mentioned dependencies are "wrong CPU type", while the two latter ones are fine. This scenario does not, however, explain to me why install/run (outside of VS) works fine on the source laptop (shouldn't it not work if VS is packaging a mix of 32 and 64 bit dependencies?). In fact, running the application through Dependency Walker on the source laptop reveals the exact same thing as on the target laptop - the same 3 dependencies are "wrong CPU type", yet the application runs here.
I do not see an option in VS to change the "setup" project to read the 64 bit filepath. I have tried manually swapping in the 64-bit DLLs at various stages (including restarting the computer between DLL swap and application run), which did not seem to have any effect. In fact, I tried replacing the 3 relevant DLLs in the System32 folder with the DLLs from the SysWOW64 folder (my idea of a cheap workaround for not being able to change the filepath - just change the file) and this just caused me to get the same error on my source laptop as I had been getting on my target laptop.
All of this stuff is relatively new to me, so please let me know if I'm foolishly overlooking some fundamental detail with my process/project - at this point it would be nice if that were the case and this is easy to fix.
Wrote this before I noticed the above comment had already answered.
Just leaving it in.
Debug Binary: Looks like you have deployed a debug version of your binary (The D in the file name: MSVCP140D.dll). Try to compile in Release mode and deploy the new binary.
Cause: Debug binaries generally need the debug-versions of the VCRedist binaries to exist on the box you try to run the binary - they are only available on developer PCs with the SDK (and / or Visual Studio) installed. That error message: 0xc000007b means "STATUS_INVALID_IMAGE_FORMAT".
Tips: There are some resource links here and some tips on how to debug deployment problems.