Win32 DLL problem: Extension crashes when using FILE *

rwgk at my-deja.com rwgk at my-deja.com
Thu Aug 10 21:36:01 EDT 2000


I am using Visual C++ 6.0 to compile a Python extension module for
Python 1.5.2 (binary distribution) on Windows98 second edition. My
configuration of the Visual C++ 6.0 project is described in detail
below.

I seem to have the exact same problem described at
http://starship.python.net/crew/kernr/mingw32/Notes.html
even though I am using Visual C++ 6.0 and not GCC/mingw32.

Most methods in the extension module work fine, however:

>>> import myextension
>>> foo = myextension.new_object()
>>> foo

*** Horrible, disgusting crash. ***

The starship web page explains:

    Always use MSVCRT.dll: The official Win32 Python distribution is
    linked against MSVCRT.dll. Extension modules compiled against
    CRTDLL.dll work in many instances, but will cause crashes
    sometimes. For example, when a FILE * pointer is passed from the
    extension to any function from python15.dll, the interpreter will
    crash. Similarly, whenever the interpreter tries to print the
    representation of an extension object, it will also crash:

I have been trying very hard to find out how I can force Visual C++ 6.0
to link against MSVCRT.dll. Unfortunately to no avail. Does anybody
know what settings to use?

Thanks for any help!
        Ralf



The following is based on the file PC/example_nt/example.txt in the
Python distribution.


Example Python extension for Windows 98 & Microsoft Visual C++ 6.0
==================================================================

Creating a brand new project
----------------------------

Create a new directory, e.g. "C:\users\jack\example."
Copy the files "example.c" and "example.def" into that directory.

Start -> Programs -> Microsoft Visual C++ 6.0 -> Microsoft Visual C++
6.0

>From the main VC60 menu select File->New. Select "Win32 Dynamic-Link
Library" from the list in the Projects Tab. Next set the "Location",
e.g., "C:\users\jack." After that enter the "Project name", e.g.
"example." (As soon as you start typing the Project name, the Location
box will be updated. I.e., the Location will automatically become
"C:\users\jack\example.") Verify that "Create new workspace" is checked
and click "OK."

A new dialog appears, with the header "Win32 Dynamic-Link Library -
Step 1 of 1." Verify that "An empty DLL project" is checked and click
"Finish."

A new dialog "New Project Information" appears. Click "OK."

>From the main VC60 menu select Project -> Add To Project -> Files.
Use the file browser to select "C:\users\jack\example\example.c" and
click "OK." Repeat the step to add "example.def" to the project.

>From the main VC60 menu select Project -> Settings. The "Project
Settings" dialog appears. Click the "C/C++" tab. At the top of the page
select the "Category: Preprocessor." In the "Additional Include
Directories" box enter the path to the Python.h include file. E.g.,
"C:\Program Files\Python\include." (Unfortunately there is no file
browser for this box. Use the Windows Start -> Find dialog to search
for Python.h if you do not know to path.)

Click the "Link" tab of the "Project Settings" dialog. At the top
of the page, select the "Category: General." In the "Object/library
modules" box add "python15.lib" to the end of the list. Select the
"Category: Input." In the "Additional library path" box enter the path
to python15.lib. E.g., "C:\Program Files\Python\libs."

Close the "Project Settings" dialog by clicking "OK."

>From the main VC60 menu select Build -> Build example.dll.
Done.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list