blob: 1eef4d27470edd5506250beb2653538463b04d9e [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 Rossum0e6ae931997-08-13 19:53:11 +000014/* Return whether this is Win32s, i.e., Win32 API on Win 3.1(1).
15 This function is exported! */
16
17BOOL 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 Rossum6dbd1901996-08-21 15:03:37 +000029
30FILE *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 Rossum3db41031996-08-23 18:42:39 +000037 strcpy(moduleKey, "Software\\Python\\PythonCore\\" MS_DLL_ID "\\Modules\\");
Guido van Rossum6dbd1901996-08-21 15:03:37 +000038 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 Rossum22822d71997-05-08 23:43:52 +000042 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
Guido van Rossum6dbd1901996-08-21 15:03:37 +000043 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}