Skip to content

Commit

Permalink
Merge pull request #80 from thegoodtgg/startup_as_subprocess
Browse files Browse the repository at this point in the history
fix: failed to load python when startup as subprocess.
  • Loading branch information
skywind3000 committed Jun 19, 2024
2 parents b70a575 + 2bec341 commit d743904
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions PyStand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//=====================================================================
//
// PyStand.cpp -
// PyStand.cpp -
//
// Created by skywind on 2022/02/03
// Last Modified: 2023/03/17 20:06
Expand Down Expand Up @@ -82,7 +82,7 @@ std::wstring PyStand::Ansi2Unicode(const char *text)


//---------------------------------------------------------------------
// init: _args, _argv, _cwd, _pystand, _home, _runtime,
// init: _args, _argv, _cwd, _pystand, _home, _runtime,
//---------------------------------------------------------------------
bool PyStand::CheckEnviron(const wchar_t *rtp)
{
Expand Down Expand Up @@ -192,11 +192,12 @@ bool PyStand::LoadPython()

// python dll must be load under "runtime"
SetCurrentDirectoryW(runtime.c_str());
SetDllDirectoryW(runtime.c_str());
// LoadLibrary
_hDLL = (HINSTANCE)LoadLibraryA("python3.dll");
if (_hDLL) {
_Py_Main = (t_Py_Main)GetProcAddress(_hDLL, "Py_Main");
}
}

// restore director
SetCurrentDirectoryW(previous.c_str());
Expand Down Expand Up @@ -317,7 +318,7 @@ int PyStand::DetectScript()
//---------------------------------------------------------------------
// init script
//---------------------------------------------------------------------
const char *init_script =
const char *init_script =
"import sys\n"
"import os\n"
"import copy\n"
Expand Down Expand Up @@ -379,7 +380,7 @@ const char *init_script =
//---------------------------------------------------------------------

//! flag: -static
//! src:
//! src:
//! link: stdc++, shlwapi, resource.o
//! prebuild: windres resource.rc -o resource.o
//! mode: win
Expand All @@ -388,7 +389,7 @@ const char *init_script =
#ifdef PYSTAND_CONSOLE
int main()
#else
int WINAPI
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
#endif
{
Expand Down

0 comments on commit d743904

Please sign in to comment.