[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
Paul Moore added the comment: > PathAllocCombine() is Windows 8+, so sample code that uses it would only be > for Python 3.9+. Yeah, I'm probably going to remove that. I mainly used it because I'm *so* spoiled by Python, writing code in C where I have to actually implement stuff for myself

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Eryk Sun
Eryk Sun added the comment: > uses a code snippet like this. PathAllocCombine() is Windows 8+, so sample code that uses it would only be for Python 3.9+. I'd prefer the function pointer to be returned as an out parameter, and return an HRESULT status as the result. If LoadLibraryExW() or

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
Paul Moore added the comment: > I think here you're in a very small minority who could get away with this, > and so I'd hesitate to make it sound like the recommended approach. Well, the evidence here is that maybe even I shouldn't be doing this :-) > What I'd actually recommend (on

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
Paul Moore 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, _path ); if (hr != S_OK) {

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Steve Dower
Steve Dower added the comment: > I wonder whether it would be worth having a section in the docs somewhere > explaining how to do this, or more generally what the "best practices" are > for embedding? Yes, it would be great. I think there are a few pieces in Doc/using/windows.rst already,

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
Paul Moore added the comment: Thanks, I'll give that a try. It sounds like I'm just using the APIs incorrectly, which would be good (in the sense that I can do what I wanted, I just didn't know how ;-)) I wonder whether it would be worth having a section in the docs somewhere explaining

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Eryk Sun
Eryk Sun added the comment: I noted that the path to "python3.dll" must be fully qualified. But let me stress that point. You cannot use the relative path "path/to/python3.dll" with LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR. The loader will fail the call as an invalid parameter. Unlike POSIX, a

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Eryk Sun
Eryk Sun added the comment: > h = LoadLibraryW(L"some/path/to/python3.dll") You should be using LoadLibraryExW(). It's a one-time call. You do not need to set the default flags via SetDefaultDllDirectories(). -- ___ Python tracker

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Eryk Sun
Eryk Sun added the comment: > So I need to dynamically load *both* python3.dll and python39.dll, > but if I do that I can get the functions from python3.dll? No, just load the fully-qualified name of "python3.dll", with the loader flags LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
Paul Moore added the comment: Thinking about what you said, "the loader waits to load it until first accessed via GetProcAddress()" did you mean by that, that the following code should work: h = LoadLibraryW(L"some/path/to/python3.dll") py_main = GetProcAddress(h, "Py_Main") (with

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
Paul Moore added the comment: So I need to dynamically load *both* python3.dll and python39.dll, but if I do that I can get the functions from python3.dll? What's the point in doing that? Surely I might as well just load python39.dll and get the functions from there, in that case. I hoped

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Eryk Sun
Eryk Sun added the comment: "python3.dll" doesn't directly depend on "python39.dll", so the loader waits to load it until first accessed via GetProcAddress(). It should remember the activation context of "python3.dll", such as whether it was loaded with a fully-qualified path and

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Jeremy Kloth
Change by Jeremy Kloth : -- nosy: +jkloth ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43022] Unable to dynamically load functions from python3.dll

2021-01-25 Thread Paul Moore
New submission from Paul Moore : I am writing a small application using the embedded distribution to run a script supplied by the user. The requirements are very simple, so all I need to do is set up argv and call Py_Main. I'm trying to load the Py_Main function dynamically (for flexibility