Teks sumber — English
Terjemahan — Bahasa Indonesia
This chapter briefly explains how to create a Windows extension module for Python using Microsoft Visual C++, and follows with more detailed background information on how it works. The explanatory material is useful for both the Windows programmer learning to build Python extensions and the Unix programmer interested in producing software which can be successfully built on both Unix and Windows.
Bab ini menjelaskan secara singkat cara membuat modul ekstensi Windows untuk Python menggunakan Microsoft Visual C++, dan diikuti dengan informasi latar belakang yang lebih rinci tentang cara kerjanya. Materi penjelasan berguna untuk pemrogram Windows yang belajar membuat ekstensi Python dan pemrogram Unix yang tertarik untuk memproduksi perangkat lunak yang dapat dibangun di Unix dan Windows.
This chapter mentions a number of filenames that include an encoded Python version number. These filenames are represented with the version number shown as ``XY``; in practice, ``'X'`` will be the major version number and ``'Y'`` will be the minor version number of the Python release you're working with. For example, if you are using Python 2.2.1, ``XY`` will actually be ``22``.
Bab ini menyebutkan sejumlah nama file yang menyertakan nomor versi Python yang disandikan. Nama file ini diwakili dengan nomor versi yang ditampilkan sebagai ``XY``; dalam praktiknya, ``'X'`` akan menjadi nomor versi utama dan ``'Y'`` akan menjadi nomor versi minor dari rilis Python yang sedang Anda kerjakan. Misalnya, jika Anda menggunakan Python 2.2.1, ``XY`` sebenarnya akan menjadi ``22``.
There are two approaches to building extension modules on Windows, just as there are on Unix: use the ``setuptools`` package to control the build process, or do things manually. The setuptools approach works well for most extensions; documentation on using ``setuptools`` to build and package extension modules is available in :ref:`setuptools-index`. If you find you really need to do things manually, it may be instructive to study the project file for the :source:`winsound <PCbuild/winsound.vcxproj>` standard library module.
In Windows, there are two types of library, a static library and an import library (both called :file:`.lib`). A static library is like a Unix :file:`.a` file; it contains code to be included as necessary. An import library is basically used only to reassure the linker that a certain identifier is legal, and will be present in the program when the DLL is loaded. So the linker uses the information from the import library to build the lookup table for using identifiers that are not included in the DLL. When an application or a DLL is linked, an import library may be generated, which will need to be used for all future DLLs that depend on the symbols in the application or DLL.
In Windows, using an import library is sort of like using ``import spam``; it gives you access to spam's names, but does not create a separate copy. On Unix, linking with a library is more like ``from spam import *``; it does create a separate copy.
Using DLLs in Practice
Windows Python is built in Microsoft Visual C++; using other compilers may or may not work. The rest of this section is MSVC++ specific.