[Request]: Adjust documentation and sample code for AMF DLL loading to avoid searching unnecessary directories
Is your feature request related to a problem? Please describe.
The current AMF documentation recommends the following to load the AMF DLL on Windows:
The AMF run-time is supplied as part of the Windows driver installation. The AMF run-time DLL should be loaded dynamically using the
LoadLibraryWWin32 function. The name of the DLL is defined by theAMF_DLL_NAMEmacro. Always pass theAMF_DLL_NAMEmacro toLoadLibraryWinstead of the actual DLL name to ensure code portability as the name might be defined differently depending on the platform:HMODULE hAMFDll = LoadLibraryW(AMF_DLL_NAME);
Using LoadLibrary() (rather than LoadLibraryEx() with LOAD_LIBRARY_SEARCH_* flags) isn't ideal because it includes ton of unnecessary directories on the search path (including everything on PATH).
Describe the solution you'd like
Adjusting the documentation to advise developers to use a more specific search path like:
LoadLibraryExW(AMF_DLL_NAME, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)
This will avoid matching a copy of the AMF runtime DLL located in some other unintended directory (particularly on a non-AMD system where there may be no legitimate AMF runtime DLL present at all).
Describe alternatives you've considered N/A
Additional context N/A
Thanks for bringing this in. There is a dilemma here: it will be inconvenient for AMF dev team to change the sample code the way you suggested because a good portion of our testing is based on alternative DLL location. You can imagine that we use common code in test apps and we use sample apps for testing. And changing just documentation makes it inconsistent with the sample code. On another hand, the problem you describes could arise only if someone starts shuffling DLL(s) around. What could be the reason for such thing? Note, that it could be a case when AMF runtime DLL is present on non-AMD setup: for example, AMD driver was installed and later GPU was changed. But in this case AMF would return error during initialization which calling application should handle anyway. In the end, the code you refer is just sample code.