<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD></HEAD>
<BODY>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>Hello all,</DIV>
<DIV> </DIV>
<DIV>After following some examples around the web, and some discussions in the
mail list,</DIV>
<DIV>I came into the following snippet to call a function defined in a Python
script into a C# host app,</DIV>
<DIV>as seen at “<A
title=http://mail.python.org/pipermail/pythondotnet/2007-June/000620.html
href="http://mail.python.org/pipermail/pythondotnet/2007-June/000620.html">http://mail.python.org/pipermail/pythondotnet/2007-June/000620.html</A>”:</DIV>
<DIV> </DIV>
<DIV>//</DIV>
<DIV>public static void MethodThatCallsPython()</DIV>
<DIV> {</DIV>
<DIV> // have
to acquire the GIL to safely call back into Python!!</DIV>
<DIV> IntPtr
state = PythonEngine.AcquireLock();</DIV>
<DIV> </DIV>
<DIV>
PythonEngine.RunSimpleString("print 'hello'");</DIV>
<DIV> </DIV>
<DIV> // done
using python for now, so release the GIL...</DIV>
<DIV>
PythonEngine.ReleaseLock(state);</DIV>
<DIV> }</DIV>
<DIV>//</DIV>
<DIV> </DIV>
<DIV>Although it looks quite simple, VS2010 this throws an exception at the very
first line of code:</DIV>
<DIV>“Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.”</DIV>
<DIV> </DIV>
<DIV>My machine runs Windows 7 64-bit, and as I read somewhere else, 64 bit OS
may be a matter of concern.</DIV>
<DIV>Does anyone know how to overcome this annoying situation??</DIV>
<DIV> </DIV>
<DIV>Thank you for any help provided!</DIV>
<DIV> </DIV>
<DIV>Igor Fier</DIV>
<DIV>Dept. of Physics, Condensed Matter</DIV>
<DIV>UNESP Rio Claro – Rio Claro-SP, Brazil</DIV></DIV></DIV></BODY></HTML>