473,545 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A solution to the MSVCRT vs MSVCR71 problem?


This question has been asked many times, and last time I was accused of
spreading FUD. So now I will rather propose a solution.

The reason for the problem is as follows:

The binary installer for Python built by te python.org team is compiled
with Microsoft Visual Studio 2003. It is linked with the C runtime
msvcrt71.dll. The copyright to msvcrt71.dll is owned by Microsoft, and
it is not an integral part of the Windows operating system. This leads
to two distinct problems:

Problem 1: You want to use a particular compiler to build a Python
extension library, but it links with the wrong CRT. Typical examples
are MinGW, Microsoft Visual C++ 6.0 and Microsoft Visual C++ Express.
There is a remedy for MinGW, but not for the other two.

Problem 2: You want to distribute a program created Py2Exe, but has no
license for Visual Studio 2003. You are therefore not allowed to
redistribute msvcrt71.dll. But without this DLL your program will not
work. As a side note: Visual Studio 2003 is out of sale, so if you
don't have it already you may be out of luck.

The solution: modify the IAT of to use the correct binary.

The process is really simple:

Solution to problem 1:

Compile with your compiler or choice, never mind which CRT are used.
Use a 'dumpbin' program, find all references to msvcrt in the binary
DLL file. Create a dll with name "py_crt" that exports these functions
but redirects them to msvcrt71. That is, in the file py_crt.def we put
something like

EXPORTS
malloc=msvcr71. malloc
free=msvcr71.fr ee
etc.

Compile the DLL py_crt.dll and then open your pyd file in binary mode.
Exchange all occurances of the string "msvcrt" (or any other CRT name)
with "py_crt". Now your binary should work just fine. What you need to
make sure is just that the name of the proxy has the same number of
letters as the CRT your compiler linked. So if it is msvcrt81.dll, e.g.
use something like py_crt81.dll instead of py_crt.dll.

Solution to problem 2:

This would be the opposite, involving modifying Python25.dll and all
pyd and dll files gathered by Py2Exe to use msvcrt.dll instead of
msvcr71.dll. One could e.g. create a DLL called py_cr71.dll that
redirects CRT calls to msvcrt.dll or any other CRT of choice. In
py_cr71.def we would then have:

EXPORTS
malloc=msvcrt.m alloc
free=msvcrt.fre e
etc.

And then it is simply a matter of modifying the binaries to load
py_cr71.dll instead of msvcrt71.dll.

What we need to make this work:

1. A dumpbin facility similar to the one that ships with Visual Studio
that can be freely distributed.

2. A python script that parses the output from dumpbin, creates the
proxy and redirects the CRT. (I already have such a script working.)

Finally, a setup script (setup.py) could automate this task for
"problem 1" above.

Another variant of the fake-CRT procedure, which would also work, is to
create a fake msvcrt71.dll that redirects to your CRT of choice, and
replace the msvcrt71.dll that came with Python with that. That is
conceptually simpler, as it involves not binary modifications, but
someone might mistake your msvcrt71.dll for the msvcrt71.dll from
Microsoft. Also antivirus-software might not like attempts to load such
a DLL as it would look like your program is hijacked by a trojan
(although it is not).

What do you think?

Jan 21 '07 #1
7 3426
sturlamolden schrieb:
Problem 2: You want to distribute a program created Py2Exe, but has no
license for Visual Studio 2003. You are therefore not allowed to
redistribute msvcrt71.dll. But without this DLL your program will not
work. As a side note: Visual Studio 2003 is out of sale, so if you
don't have it already you may be out of luck.
I believe this problem doesn't exist. Licensees of Python are permitted
to redistribute mscvr71.dll, as long as they redistribute it in order
to support pythonxy.dll. The EULA says

# You also agree not to permit further distribution of the
# Redistributable s by your end users except you may permit further
# redistribution of the Redistributable s by your distributors to your
# end-user customers if your distributors only distribute the
# Redistributable s in conjunction with, and as part of, the Licensee
# Software, you comply with all other terms of this EULA, and your
# distributors comply with all restrictions of this EULA that are
# applicable to you.

In this text, "you" is the licensee of VS 2003 (i.e. me, redistributing
msvcr71.dll as part of Python 2.5), and the "Redistributabl e" is
msvcr71.dll. The "Licensee Software" is "a software application product
developed by you that adds significant and primary functionality to the
Redistributable s", i.e. python25.dll.

IANAL; this is not legal advise.

Regards,
Martin
Jan 21 '07 #2
At Sunday 21/1/2007 00:07, sturlamolden wrote:
>Solution to problem 1:

Compile with your compiler or choice, never mind which CRT are used.
Use a 'dumpbin' program, find all references to msvcrt in the binary
DLL file. Create a dll with name "py_crt" that exports these functions
but redirects them to msvcrt71. That is, in the file py_crt.def we put
something like

EXPORTS
malloc=msvcr71 .malloc
free=msvcr71.f ree
etc.

Compile the DLL py_crt.dll and then open your pyd file in binary mode.
Exchange all occurances of the string "msvcrt" (or any other CRT name)
with "py_crt". Now your binary should work just fine. What you need to
make sure is just that the name of the proxy has the same number of
letters as the CRT your compiler linked. So if it is msvcrt81.dll, e.g.
use something like py_crt81.dll instead of py_crt.dll.

Solution to problem 2:
[modify external references inside python25.dll to use a different runtime]
This would only work, if runtime dll's were compatibles between them,
and they are not. You can't blindly redirect a call to msvcr71.__xyz
to msvcr80.__xyz and expect that to work magically - it may have a
different number of arguments, or different types, or even may not
exist anymore.
(And what about any symbol exported by ordinal?)
--
Gabriel Genellina
Softlab SRL


_______________ _______________ _______________ _____
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 21 '07 #3
Gabriel Genellina schrieb:
This would only work, if runtime dll's were compatibles between them,
and they are not. You can't blindly redirect a call to msvcr71.__xyz to
msvcr80.__xyz and expect that to work magically - it may have a
different number of arguments, or different types, or even may not exist
anymore.
Actually, the libraries *are* binary-compatible (on the ABI level). You
just can't mix two libraries in a single program easily.
(And what about any symbol exported by ordinal?)
That doesn't happen for msvcrt, as the import library links by name.

Regards,
Martin
Jan 21 '07 #4
At Sunday 21/1/2007 05:38, Martin v. Löwis wrote:
>Gabriel Genellina schrieb:
This would only work, if runtime dll's were compatibles between them,
and they are not. You can't blindly redirect a call to msvcr71.__xyz to
msvcr80.__xyz and expect that to work magically - it may have a
different number of arguments, or different types, or even may not exist
anymore.

Actually, the libraries *are* binary-compatible (on the ABI level). You
just can't mix two libraries in a single program easily.
That's a good thing - but is this just by accident, or is documentedsomew here?
I remember that I tried something like that in
the past, and failed. (Perhaps earlier versions
where not fully backwards compatible - or I didn't try hard enough thattime).
--
Gabriel Genellina
Softlab SRL


_______________ _______________ _______________ _____
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 21 '07 #5

Gabriel Genellina wrote:
This would only work, if runtime dll's were compatibles between them,
and they are not.
It is standard C, defined by ANSI and ISO.

Jan 21 '07 #6
Gabriel Genellina schrieb:
That's a good thing - but is this just by accident, or is documented
somewhere?
It's documented somewhere (although I can't find the documentation
right now - it explains how you can link object files from a static
library compiled with an older compiler version against a new version
of the C library).
I remember that I tried something like that in the past, and failed.
(Perhaps earlier versions where not fully backwards compatible - or I
didn't try hard enough that time).
It's been that way for ages, atleast since they started to support
32-bit code. So if you had problems, they might have had a different
source.

It's a different thing for the C++ libraries, though.

Regards,
Martin
Jan 21 '07 #7
sturlamolden schrieb:
>This would only work, if runtime dll's were compatibles between them,
and they are not.

It is standard C, defined by ANSI and ISO.
ANSI and ISO don't define the ABI, though. For example, the definition
of the FILE type might (and does) vary across compilers, even if all
these compilers implement C99.

Regards,
Martin
Jan 21 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2314
by: dbrown2 | last post by:
I'm having some trouble using kbhit inside the editor enviroments. I'm using win2000 with Python2.3 and win32all v157 versions. Any pointer on how this should be handled would be appreciated. Is there another non-blocking way to detect a key press? Here's the code that is causing the trouble. If I run this by double-clicking then it...
4
5118
by: Baga | last post by:
Our product is compiled with /MD switch, so it uses MSVCRT.DLL But as every system configuration that we support includes this file anyway, we do not actually redistribute it, instead we use the one which is already present. However, when we compile with /MD switch on .NET 2003, MSVCR71.DLL is used instead, and it is not required to be...
3
3848
by: Sara Shoemaker | last post by:
I am having problems creating a stand-alone Windows app. I am using a .vcproj file that was translated from a Qt project file using the Qt plug-in. My problem is in getting it statically linked to the Windows libraries. After Googling extensively and getting .NET to generate a sample project I have made the following changes to my...
1
2345
by: Fabuio | last post by:
Hi, we are writing a program which uses some third party APIs librares. Those APIs are dinamically linked to the MSVCR71.DLL. Unfortunately, we are compiling with the C++ DOT NET 7, which uses the MSVCR70.DLL. This means, that we are able to compile, but when in our code we try to call some function of the MSVCR7x.DLL, the program...
0
1437
by: bluter | last post by:
I have a problem with some VC++ (v5 sp3 compiled in debug mode) server component which perfrom Data Acces. These have been in production on NT4.0 and w2k. However when we try to use them on Server 2003 we only get partial functionality. So far we have noticed that when the components are returning large set of data that they fail. The...
48
4896
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott David Daniels where he said that probably the VS2003 toolkit will be used for Python 2.5 again. However, even before the release of Python 2.5, I...
2
3485
by: Konte | last post by:
Are there news about the impossibility of redistributing msvcr71.ddl with own stand-alone application written in python for who doesn't have MSVC7 license?
18
81254
by: =?Utf-8?B?RGF2aWQ=?= | last post by:
I have a VC++ / .NET 2.0 solution built using VS 2005 SP1 under XP. Everything has been working well there over the past year. I have recently starting porting the app to Windows Vista (since it currently will not execute properly there). I installed VS 2005 SP1 and the hot fix SP for Vista on my Windows Vista system and have rebuilt the...
11
20649
by: Dick Moores | last post by:
Windows XP Pro, Python 2.5.1 import msvcrt while True: if msvcrt.kbhit(): key = msvcrt.getch() if key == 'Enter' do something Is there a way to catch the pressing of the 'Enter' key?
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7771
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.