This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.moore
Recipients eryksun, jkloth, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-01-25.21:02:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611608540.9.0.500872109484.issue43022@roundup.psfhosted.org>
In-reply-to
Content
Confirmed. The following code works as I want:

Py_Main_t get_pymain(wchar_t *base_dir) {
    wchar_t *dll_path;
    HRESULT hr = PathAllocCombine(
        base_dir, L"python\\python3.dll",
        PATHCCH_ALLOW_LONG_PATHS, &dll_path
    );
    if (hr != S_OK) {
        error(L"Could not construct Python DLL path");
    }

    HMODULE py_dll = LoadLibraryExW(dll_path, 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
    if (!py_dll) {
        error(L"Could not load Python DLL %ls", dll_path);
    }
    LocalFree(dll_path);

    Py_Main_t py_main = (Py_Main_t)GetProcAddress(py_dll, "Py_Main");
    if (!py_main) {
        error(L"Could not locate Py_Main function");
    }

    return py_main;
}


If people think it's worthwhile, I can put together a change to https://docs.python.org/3/extending/embedding.html#embedding-python-in-another-application (maybe a new section, "Embedding on Windows by dynamically loading the stable ABI"?) that uses a code snippet like this.
History
Date User Action Args
2021-01-25 21:02:20paul.mooresetrecipients: + paul.moore, tim.golden, jkloth, zach.ware, eryksun, steve.dower
2021-01-25 21:02:20paul.mooresetmessageid: <1611608540.9.0.500872109484.issue43022@roundup.psfhosted.org>
2021-01-25 21:02:20paul.moorelinkissue43022 messages
2021-01-25 21:02:20paul.moorecreate