1
votes

I'm writing a program that needs to run across Windows 7, 8.x and 10. The program has a one (relatively minor) feature that relies on Windows APIs that are only available on Windows 10. This feature will obviously not work on Win7, and before calling these APIs I make sure that the current OS is Windows 10.

In order to use these APIs I'm forced to configure my VS2015 project to "Consume Windows Runtime Extension" (/ZW) and to set "Target Platform Version" to 10.0.10586.0.

However, this causes a problem when I try to run the app on Windows 7. I get an error dialog saying "The program can't start because api-ms-win-core-winrt-string-l1-1-0.dll is missing from your computer". I tried to installed VS2015 redistributable package on the Win7 machine, but that did not solve the problem.

Any idea on how to get this to run on Win7? I really prefer not to change all my code to dynamically load all Windows 10 functions.

The program is written in C++, and the Windows API I use are from Windows.Devices.WifiDirect namespace.

2
Is this really about C# or rather C++? And what is the API that you are using? There is likely a solution that works within a classic desktop application.Dirk Vollmar
An obvious limitation of a Windows 10 only application. No matter what is your good will, it will not work.Lex Li
A nice feature of a C# program is that it only loads DLLs when you use their code. Decorating the method with [MethodImpl(MethodImplOptions.Noinlining)] is best. But clearly you are not talking about C#, the /ZW option is a C++/CX compile option. Calling a WinRT/UWP method from C# is easy as well, you however have to edit the project file by hand to add the required <TargetPlatformVersion> element. Now you add a reference to a WinRT library.Hans Passant
Sorry guys, I forgot to mention this is a C++ program. The Windows API I use are from Windows.Devices.WifiDirect namespace.greenmind
@HansPassant, Will your suggestion solution work for a C++ project? I'm not sure I understood your proposal.greenmind

2 Answers

1
votes

I ended up solving this problem by moving all my Win10-only API calls into a proxy DLL, which is compiled with /ZW. I then removed the /ZW switch from the main program, which then allowed it to run under Windows 7. The proxy DLL is only loaded (using LoadLibrary() call) when my program is running on a Windows 10 machine.

This solved the problem. I did have to write a few proxy functions for the DLL, but it was far lass overhead than doing that for all the Win10-only API calls.

I would still like to hear better solutions, if there are any.

1
votes

It is possible to access Windows 10 APIs without using /ZW switch by using the "ABI" API. More details here:

https://blogs.msdn.microsoft.com/oldnewthing/20160629-00/?p=93775

You'll have to use APIs like "RoGetActivationFactory" and "WindowsCreateString" through LoadLibrary/GetProcAddress, since you can't link to them as they're not available on Windows 7. Don't forget to define your WINVER and _WIN32_WINNT to Windows 7:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx

That will allow you to not link to any APIs not available on Windows 7.