Author eryksun
Recipients Artfunkel, Igor.Skochinsky, Keno Fischer, amaury.forgeotdarc, asvetlov, belopolsky, cgohlke, dancol, eryksun, ezio.melotti, mark.dickinson, meador.inge, palm.kevin
Date 2016-07-09.12:08:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is only a problem for ctypes when python27.dll is used in an application that isn't manifested to load the "Microsoft.VC90.CRT" assembly. ctypes doesn't have this problem for a regular script run via the 2.7 version of python.exe, since the loader uses the python.exe activation context. Daniel claimed otherwise, but his claim is demonstrably false. Maybe he was embedding Python.

Keno, I don't think it's a good idea to arbitrarily set the Python DLL's activation context every time ctypes calls LoadLibrary. I proposed a more generic solution in issue 24429, msg246754.

An alternative solution would be to implement a pure-Python activation context class that works as a Python context manager. For example, it could create and activate a context using the hModule and lpResourceName fields:

    with ctypes.ACTCTX(module_handle=sys.dllhandle, 
        libc = ctypes.CDLL('msvcr90')

I have a Stack Overflow answer that demonstrates using activation contexts with ctypes:
Date User Action Args
2016-07-09 12:08:21eryksunsetrecipients: + eryksun, amaury.forgeotdarc, mark.dickinson, belopolsky, ezio.melotti, asvetlov, cgohlke, meador.inge, palm.kevin, dancol, Igor.Skochinsky, Artfunkel, Keno Fischer
2016-07-09 12:08:21eryksunsetmessageid: <>
2016-07-09 12:08:21eryksunlinkissue17213 messages
2016-07-09 12:08:21eryksuncreate