<!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>&nbsp;</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>&nbsp;</DIV>
<DIV>//</DIV>
<DIV>public static void MethodThatCallsPython()</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // have 
to acquire the GIL to safely call back into Python!!</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IntPtr 
state = PythonEngine.AcquireLock();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
PythonEngine.RunSimpleString("print 'hello'");</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // done 
using python for now, so release the GIL...</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
PythonEngine.ReleaseLock(state);</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>//</DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV>Thank you for any help provided!</DIV>
<DIV>&nbsp;</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>