Windows-rs: Support loading dll at runtime

Created on 21 Jan 2021  ·  7Comments  ·  Source: microsoft/windows-rs

Sorry if this is out of scope, but it's a cool idea I had: It'd be nice if windows-rs provided a way to generate stubs that load the dlls at runtime and call the function indirectly (using LoadLibraryEx/GetProcAddress), returning an error if the function does not exist.

This would provide an easy way to target older versions of Windows. I imagine the API would look similar to what windows-dll provides.

enhancement

Most helpful comment

Yep, I'm planning to find some way to use the SupportedOSPlatform attribute to conditionally delay load. It's very tailored to C# but I'm hopeful I can make it work.

All 7 comments

I plan to add an option to use this crate in windows-dll under the hood at some point, I'm not sure how much if any extra work it would be to generate windows-rs compatible function signatures though.

Thanks for the suggestion @roblabla! We could certainly add an option to generate delay load wrappers, perhaps as an option in the build macro for all or select functions.

Would love to see this too. It even seems windows-rs already does this internally for some functions using the demand_load! macro.

For performance reasons, I think it would make sense to have it limited to a selected set of functions. Does https://github.com/microsoft/win32metadata also include data on the Windows version in which the corresponding API was introduced? If so, this could potentially be done automatically using a minimum version parameter.

Does https://github.com/microsoft/win32metadata also include data on the Windows version in which the corresponding API was introduced? If so, this could potentially be done automatically using a minimum version parameter.

It seems it does in form of SupportedOSPlatform:
image

Yep, I'm planning to find some way to use the SupportedOSPlatform attribute to conditionally delay load. It's very tailored to C# but I'm hopeful I can make it work.

Yep, I'm planning to find some way to use the SupportedOSPlatform attribute to conditionally delay load. It's very tailored to C# but I'm hopeful I can make it work.

In the Win32 metadata file we're looking at here, are there any of these version strings that aren't just a version (series of numbers separated by dots) prefixed by "windows"? From a cursory look in ILspy, I couldn't find any, but that wasn't an exhaustive check. I did find several functions that lacked the appropriate metadata, though 😕

Yes, this is a .NET invention that I'll have to parse. Looks like a reasonably closed set of possibilities.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zymlex picture Zymlex  ·  3Comments

13r0ck picture 13r0ck  ·  4Comments

bdbai picture bdbai  ·  3Comments

ZCWorks picture ZCWorks  ·  3Comments

rylev picture rylev  ·  4Comments