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 | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 14 | extern BOOL PyWin_IsWin32s(); |
| 15 | |
| 16 | FILE *PyWin_FindRegisteredModule( const char *moduleName, struct filedescr **ppFileDesc, char *pathBuf, int pathLen) |
| 17 | { |
| 18 | char moduleKey[128]; |
| 19 | struct filedescr *fdp = NULL; |
| 20 | FILE *fp; |
| 21 | int modNameSize = pathLen; |
| 22 | HKEY keyBase = PyWin_IsWin32s() ? HKEY_CLASSES_ROOT : HKEY_LOCAL_MACHINE; |
Guido van Rossum | 3db4103 | 1996-08-23 18:42:39 +0000 | [diff] [blame] | 23 | strcpy(moduleKey, "Software\\Python\\PythonCore\\" MS_DLL_ID "\\Modules\\"); |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 24 | strcat(moduleKey, moduleName); |
| 25 | if (RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize)!=ERROR_SUCCESS) |
| 26 | return NULL; |
| 27 | // use the file extension to locate the type entry. |
Guido van Rossum | 22822d7 | 1997-05-08 23:43:52 +0000 | [diff] [blame] | 28 | for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { |
Guido van Rossum | 6dbd190 | 1996-08-21 15:03:37 +0000 | [diff] [blame] | 29 | int extLen=strlen(fdp->suffix); |
| 30 | if (modNameSize>extLen && strnicmp(pathBuf+(modNameSize-extLen-1),fdp->suffix,extLen)==0) |
| 31 | break; |
| 32 | } |
| 33 | if (fdp->suffix==NULL) |
| 34 | return NULL; |
| 35 | fp = fopen(pathBuf, fdp->mode); |
| 36 | if (fp != NULL) |
| 37 | *ppFileDesc = fdp; |
| 38 | return fp; |
| 39 | } |