blob: 022b9e5aed1cd4ba0a2101991fb7972f93fbcbf4 [file] [log] [blame]
Guido van Rossum6dbd1901996-08-21 15:03:37 +00001/********************************************************************
2
Guido van Rossumeaf9b6c1996-08-22 00:06:59 +00003 import_nt.c
Guido van Rossum6dbd1901996-08-21 15:03:37 +00004
5 Win32 specific import code.
6
7*/
8
Guido van Rossum7688bba1997-05-05 21:45:44 +00009#include "Python.h"
Guido van Rossum6dbd1901996-08-21 15:03:37 +000010#include "osdefs.h"
11#include <windows.h>
Guido van Rossum6dbd1901996-08-21 15:03:37 +000012#include "importdl.h"
13
Guido van Rossum6dbd1901996-08-21 15:03:37 +000014extern BOOL PyWin_IsWin32s();
15
16FILE *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 Rossum3db41031996-08-23 18:42:39 +000023 strcpy(moduleKey, "Software\\Python\\PythonCore\\" MS_DLL_ID "\\Modules\\");
Guido van Rossum6dbd1901996-08-21 15:03:37 +000024 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 Rossum22822d71997-05-08 23:43:52 +000028 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
Guido van Rossum6dbd1901996-08-21 15:03:37 +000029 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}