[llvm] [Support][Windows] Add utility function for retrieving a DLL-exported function (PR #97905)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 7 06:30:38 PDT 2024


================
@@ -245,6 +245,12 @@ std::error_code GetCommandLineArguments(SmallVectorImpl<const char *> &Args,
 std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16,
                           size_t MaxPathLen = MAX_PATH);
 
+/// Dynamically retrieve an exported function from a DLL, while casting it to a
+/// known type. This avoids -Wcast-function-type-mismatch.
+template <typename T> T funcFromModule(HMODULE Mod, StringRef Name) {
+  return (T)(void *)::GetProcAddress(Mod, Name.data());
+}
----------------
aganea wrote:

You can't destructure a C function pointer like this, can you? This needs `std::remove_pointer_t<>` on the calling site?

https://github.com/llvm/llvm-project/pull/97905


More information about the llvm-commits mailing list