Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 1 | /******************************************************************** |
| 2 | |
Guido van Rossum | eaf9b6c | 1996-08-22 00:06:59 +0000 | [diff] [blame] | 3 | import_nt.c |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 4 | |
| 5 | Win32 specific import code. |
| 6 | |
| 7 | */ |
| 8 | |
Guido van Rossum | 7688bba | 1997-05-05 21:45:44 +0000 | [diff] [blame] | 9 | #include "Python.h" |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 10 | #include "osdefs.h" |
| 11 | #include <windows.h> |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 12 | #include "importdl.h" |
| 13 | |
Guido van Rossum | 0e6ae93 | 1997-08-13 19:53:11 +0000 | [diff] [blame^] | 14 | /* Return whether this is Win32s, i.e., Win32 API on Win 3.1(1). |
| 15 | This function is exported! */ |
| 16 | |
| 17 | BOOL PyWin_IsWin32s() |
| 18 | { |
| 19 | static BOOL bIsWin32s = -1; /* flag as "not yet looked" */ |
| 20 | |
| 21 | if (bIsWin32s == -1) { |
| 22 | OSVERSIONINFO ver; |
| 23 | ver.dwOSVersionInfoSize = sizeof(ver); |
| 24 | GetVersionEx(&ver); |
| 25 | bIsWin32s = ver.dwPlatformId == VER_PLATFORM_WIN32s; |
| 26 | } |
| 27 | return bIsWin32s; |
| 28 | } |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 29 | |
| 30 | FILE *PyWin_FindRegisteredModule( const char *moduleName, struct filedescr **ppFileDesc, char *pathBuf, int pathLen) |
| 31 | { |
| 32 | char moduleKey[128]; |
| 33 | struct filedescr *fdp = NULL; |
| 34 | FILE *fp; |
| 35 | int modNameSize = pathLen; |
| 36 | HKEY keyBase = PyWin_IsWin32s() ? HKEY_CLASSES_ROOT : HKEY_LOCAL_MACHINE; |
Guido van Rossum | 3db4103 | 1996-08-23 18:42:39 +0000 | [diff] [blame] | 37 | strcpy(moduleKey, "Software\\Python\\PythonCore\\" MS_DLL_ID "\\Modules\\"); |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 38 | strcat(moduleKey, moduleName); |
| 39 | if (RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize)!=ERROR_SUCCESS) |
| 40 | return NULL; |
| 41 | // use the file extension to locate the type entry. |
Guido van Rossum | 22822d7 | 1997-05-08 23:43:52 +0000 | [diff] [blame] | 42 | for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 43 | int extLen=strlen(fdp->suffix); |
| 44 | if (modNameSize>extLen && strnicmp(pathBuf+(modNameSize-extLen-1),fdp->suffix,extLen)==0) |
| 45 | break; |
| 46 | } |
| 47 | if (fdp->suffix==NULL) |
| 48 | return NULL; |
| 49 | fp = fopen(pathBuf, fdp->mode); |
| 50 | if (fp != NULL) |
| 51 | *ppFileDesc = fdp; |
| 52 | return fp; |
| 53 | } |