Paul Moore <p.f.mo...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43022>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to