Index: install.c =================================================================== --- install.c (revision 69004) +++ install.c (working copy) @@ -293,13 +293,90 @@ typedef result (*__PROC__##name) args;\ result (*name)args = (__PROC__##name)GetProcAddress(dll, #name) +// A version that allows the function pointer variable to be named differently +// than the function itself. +#define DECLPROCEX(dll, result, var_name, export_name, args)\ + typedef result (*__PROC__##var_name) args;\ + result (*var_name)args = (__PROC__##var_name)GetProcAddress(dll, #export_name) #define DECLVAR(dll, type, name)\ type *name = (type*)GetProcAddress(dll, #name) typedef void PyObject; +// Convert a "char *" string to "whcar_t *", or NULL on error. +// Result string must be free'd +wchar_t *widen_string(char *src) +{ + wchar_t *result; + DWORD dest_cch; + int src_len = strlen(src) + 1; // include NULL term in all ops + /* use MultiByteToWideChar() to see how much we need. */ + /* NOTE: this will include the null-term in the length */ + dest_cch = MultiByteToWideChar(CP_ACP, 0, src, src_len, NULL, 0); + // alloc the buffer + result = (wchar_t *)malloc(dest_cch * sizeof(wchar_t)); + if (result==NULL) + return NULL; + /* do the conversion */ + if (0==MultiByteToWideChar(CP_ACP, 0, src, src_len, result, dest_cch)) { + free(result); + return NULL; + } + return result; +} +// Call PySys_SetArgv appropriately for either py2k or py3k +static int setargv(HINSTANCE hPython, int argc, char **argv) +{ + if (py_major < 3) { + DECLPROCEX(hPython, int, Py2Sys_SetArgv, PySys_SetArgv, (int, char **)); + if (!Py2Sys_SetArgv) + return 1; + Py2Sys_SetArgv(argc, argv); + } else { + // py3k version - widen the strings. + int i; + DECLPROCEX(hPython, int, Py3Sys_SetArgv, PySys_SetArgv, (int, wchar_t **)); + static wchar_t *wargv[256]; + if (!Py3Sys_SetArgv) + return 1; + memset(wargv, 0, sizeof(wargv)); + for (i=0;i