Skip to content

Instantly share code, notes, and snippets.

@tritium21
Created May 26, 2016 17:17
Show Gist options
  • Save tritium21/b4c5f25af21dbfdfbb71b3a8c823b109 to your computer and use it in GitHub Desktop.
Save tritium21/b4c5f25af21dbfdfbb71b3a8c823b109 to your computer and use it in GitHub Desktop.
#include <Python.h>
#include <windows.h>
#ifdef _CONSOLE
char script[] = "from collector import run\nimport sys\nsys.exit(run(sys.argv[1:]))";
int
wmain(int argc, wchar_t *argv[])
#else
char script[] = "from collector import run_gui\nimport sys\nsys.exit(run_gui(sys.argv[1:]))";
int WINAPI
wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#endif
{
// wchar_t *program = Py_DecodeLocale(__wargv[0], NULL);
wchar_t *program = __wargv[0];
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PySys_SetArgvEx(__argc-1, __wargv+1, 0);
PyRun_SimpleString(script);
Py_Finalize();
PyMem_RawFree(program);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment