436
❘
APPENDIX b
CPython ExtEnsions for ironPython
developer). In this case, you need to access the code within the DLL, but you probably can’t do it
from IronPython. The fastest way to overcome this problem is to use a third-party solution such as
IronClad (see the section “Working with IronClad” later in this appendix).
Another technique you can use to overcome extension problems that involve C code is to work through
the issue using P/Invoke. The section “Using C# for Win32 Support” in Chapter 16 provides a quick
view of how powerful a P/Invoke extension can be. However, sometimes it’s the detective work required
to obtain the information you need to use P/Invoke that proves the most difficult to obtain. I’ve written
a series of four articles that show some of my techniques for performing this task:
➤➤
“Working with Windows Messages in .NET” (
http://www.devsource.com/c/a/
Using-VS/Working-with-Windows-Messages-in-NET/
)
➤
➤
“Hooking Windows Messages in .NET” (
http://www.devsource.com/c/a/Using-VS/
Hooking-Windows-Messages-in-NET/
)
➤
➤
“Globally Hooking Windows Messages in .NET” (
http://www.devsource.com/c/a/
Using-VS/Globally-Hooking-Windows-Messages-in-NET/
)
➤
➤
“Special Windows Message Hooking Techniques for .NET” (
http://www.devsource
.com/c/a/Using-VS/Special-Windows-Message-Hooking-Techniques-for-NET/
)
There’s a point where you do need to give up on using a particular CPython extension with IronPython.
These situations are becoming fewer as developers come up with new tools for addressing problems and
IronPython itself becomes closer to CPython in implementation. It would be overly optimistic to say
that there will ever come a time when you can run any CPython extension using IronPython.
ObTAININg THIrD-PArTy SOluTIONS
Third-party solutions are definitely easier, in many respects, than creating your own solutions. Of
course, you have to find a third-party solution that actually performs the required task. In addition,
you can’t accept that third-party solutions come without potential problems. If you use a third-party
solution, even one that works, you always run the risk that you won’t be able to obtain help when
you need it or that the third party will choose not to update the software as needed. Even so, third-
party solutions can be very beneficial, especially when you’re on a tight time schedule. The following
sections describe some third-party solutions in general and one specifically, IronClad.
Do'stlaringiz bilan baham: |