<span style='font-family:Verdana'><span style='font-size:12px'><!--[if gte mso 9]><xml> 
 <w:WordDocument> 
  <w:View>Normal</w:View> 
  <w:Zoom>0</w:Zoom> 
  <w:TrackMoves/> 
  <w:TrackFormatting/> 
  <w:PunctuationKerning/> 
  <w:ValidateAgainstSchemas/> 
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> 
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent> 
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> 
  <w:DoNotPromoteQF/> 
  <w:LidThemeOther>EN-US</w:LidThemeOther> 
  <w:LidThemeAsian>ZH-CN</w:LidThemeAsian> 
  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> 
  <w:Compatibility> 
   <w:BreakWrappedTables/> 
   <w:SnapToGridInCell/> 
   <w:WrapTextWithPunct/> 
   <w:UseAsianBreakRules/> 
   <w:DontGrowAutofit/> 
   <w:SplitPgBreakAndParaMark/> 
   <w:DontVertAlignCellWithSp/> 
   <w:DontBreakConstrainedForcedTables/> 
   <w:DontVertAlignInTxbx/> 
   <w:Word11KerningPairs/> 
   <w:CachedColBalance/> 
   <w:UseFELayout/> 
  </w:Compatibility> 
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> 
  <m:mathPr> 
   <m:mathFont m:val="Cambria Math"/> 
   <m:brkBin m:val="before"/> 
   <m:brkBinSub m:val="&#45;-"/> 
   <m:smallFrac m:val="off"/> 
   <m:dispDef/> 
   <m:lMargin m:val="0"/> 
   <m:rMargin m:val="0"/> 
   <m:defJc m:val="centerGroup"/> 
   <m:wrapIndent m:val="1440"/> 
   <m:intLim m:val="subSup"/> 
   <m:naryLim m:val="undOvr"/> 
  </m:mathPr></w:WordDocument> 
</xml><![endif]--><!--[if gte mso 9]><xml> 
 <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" 
  DefSemiHidden="true" DefQFormat="false" DefPriority="99" 
  LatentStyleCount="267"> 
  <w:LsdException Locked="false" Priority="0" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Normal"/> 
  <w:LsdException Locked="false" Priority="9" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> 
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 1"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 2"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 3"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 4"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 5"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 6"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 7"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 8"/> 
  <w:LsdException Locked="false" Priority="39" Name="toc 9"/> 
  <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> 
  <w:LsdException Locked="false" Priority="10" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Title"/> 
  <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> 
  <w:LsdException Locked="false" Priority="11" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> 
  <w:LsdException Locked="false" Priority="22" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Strong"/> 
  <w:LsdException Locked="false" Priority="20" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> 
  <w:LsdException Locked="false" Priority="59" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Table Grid"/> 
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> 
  <w:LsdException Locked="false" Priority="1" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading Accent 1"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List Accent 1"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid Accent 1"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> 
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> 
  <w:LsdException Locked="false" Priority="34" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> 
  <w:LsdException Locked="false" Priority="29" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Quote"/> 
  <w:LsdException Locked="false" Priority="30" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List Accent 1"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List Accent 1"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading Accent 2"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List Accent 2"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid Accent 2"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List Accent 2"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List Accent 2"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading Accent 3"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List Accent 3"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid Accent 3"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List Accent 3"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List Accent 3"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading Accent 4"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List Accent 4"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid Accent 4"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List Accent 4"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List Accent 4"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading Accent 5"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List Accent 5"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid Accent 5"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List Accent 5"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List Accent 5"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> 
  <w:LsdException Locked="false" Priority="60" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Shading Accent 6"/> 
  <w:LsdException Locked="false" Priority="61" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light List Accent 6"/> 
  <w:LsdException Locked="false" Priority="62" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Light Grid Accent 6"/> 
  <w:LsdException Locked="false" Priority="63" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> 
  <w:LsdException Locked="false" Priority="64" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> 
  <w:LsdException Locked="false" Priority="65" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> 
  <w:LsdException Locked="false" Priority="66" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> 
  <w:LsdException Locked="false" Priority="67" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> 
  <w:LsdException Locked="false" Priority="68" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> 
  <w:LsdException Locked="false" Priority="69" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> 
  <w:LsdException Locked="false" Priority="70" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Dark List Accent 6"/> 
  <w:LsdException Locked="false" Priority="71" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> 
  <w:LsdException Locked="false" Priority="72" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful List Accent 6"/> 
  <w:LsdException Locked="false" Priority="73" SemiHidden="false" 
   UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> 
  <w:LsdException Locked="false" Priority="19" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> 
  <w:LsdException Locked="false" Priority="21" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> 
  <w:LsdException Locked="false" Priority="31" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> 
  <w:LsdException Locked="false" Priority="32" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> 
  <w:LsdException Locked="false" Priority="33" SemiHidden="false" 
   UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> 
  <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> 
  <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> 
 </w:LatentStyles> 
</xml><![endif]--><!--[if gte mso 10]> 
<style> 
 /* Style Definitions */ 
 table.MsoNormalTable 
        {mso-style-name:"Table Normal"; 
        mso-tstyle-rowband-size:0; 
        mso-tstyle-colband-size:0; 
        mso-style-noshow:yes; 
        mso-style-priority:99; 
        mso-style-qformat:yes; 
        mso-style-parent:""; 
        mso-padding-alt:0in 5.4pt 0in 5.4pt; 
        mso-para-margin-top:0in; 
        mso-para-margin-right:0in; 
        mso-para-margin-bottom:10.0pt; 
        mso-para-margin-left:0in; 
        line-height:115%; 
        mso-pagination:widow-orphan; 
        font-size:11.0pt; 
        font-family:"Calibri","sans-serif"; 
        mso-ascii-font-family:Calibri; 
        mso-ascii-theme-font:minor-latin; 
        mso-hansi-font-family:Calibri; 
        mso-hansi-theme-font:minor-latin; 
        mso-bidi-font-family:"Times New Roman"; 
        mso-bidi-theme-font:minor-bidi;} 
</style> 
<![endif]--> 
<p class="MsoNormal"> 
        Hi,<br /> 
        <br /> 
        Attached is a test case for the Memory Allocation problem. One folder contains two python scripts and the astyle.dll. The other contains test data. I don’t know of any Windows API functions which work the same as astyle. A callback gets a memory allocation that is used to return text to the python program. The DLL is 32 bit. Therefore you must use the 32 bit python executable to run the script. Let me know if this is a problem and I will send a 64 bit version.<br /> 
         </p> 
<p class="MsoNormal"> 
        There are two python scripts included. ExampleUnicode.py is the CPython script. It will work with either python version 2.7 or 3.2 (32 bit). The other, ExampleUnicode<strong>Iron</strong>.py, is the IronPython program. It will also work with CPython. But it doesn’t work with IronPython. I included both so you can use a diff program to see the changes. There aren’t many. I am aware of the Unicode problem with IronPython. It has been fixed and byte code is correctly being sent to the DLL.<br /> 
         </p> 
<p class="MsoNormal"> 
        The call to astyle is at line 59 or 60 in the scripts. Text_in is sent to the dll, a python memory allocation function is called, and formatted_text is returned. Formatted_text uses the memory that was allocated by the python memory allocation function.<br /> 
         </p> 
<p class="MsoNormal"> 
        AStyle is open source and can be obtained from <a href="http://sourceforge.net/projects/astyle/">http://sourceforge.net/projects/astyle/</a> .</p> 
<p class="MsoNormal"> 
        Let me know if you have questions. It is a fairly complicated process, but it works with CPython.<br /> 
        And thanks for the responses. I really wasn't very optimistic about anyone understanding the problem.</p> 
<br /> 
<br /> 
<span id="editor_signature"><span style="font-family:Verdana; font-size:12px">Jim&nbsp;Pattee<br /> 
jimp02@email.com</span></span><br /> 
<br /> 
<br /> 
<br /> 
<p style="margin:0px; padding:0px;" > 
         </p> 
<blockquote style="border-left: 1px solid #CCC; padding-left: 5px; margin-left: 5px; margin-bottom: 0px; margin-top: 0px; margin-right: 0px;" type="cite"> 
        <p style="margin:0px; padding:0px;" > 
                <span style="font-family:Verdana"><span style="font-size:12px">----- Original Message -----</span></span></p> 
        <p style="margin:0px; padding:0px;" > 
                <span style="font-family:Verdana"><span style="font-size:12px">From: Dino Viehland</span></span></p> 
        <p style="margin:0px; padding:0px;" > 
                <span style="font-family:Verdana"><span style="font-size:12px">Sent: 01/23/12 03:57 PM</span></span></p> 
        <p style="margin:0px; padding:0px;" > 
                <span style="font-family:Verdana"><span style="font-size:12px">To: Markus Schaber, Jim Pattee, ironpython-users@python.org</span></span></p> 
        <p style="margin:0px; padding:0px;" > 
                <span style="font-family:Verdana"><span style="font-size:12px">Subject: RE: [Ironpython-users] Memory Allocation in Iron Python</span></span></p> 
        <br /> 
        <div link="blue" vlink="purple"> 
                <div class="WordSection1"> 
                        <p class="MsoNormal"> 
                                <span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">One potential issue here could be ASCII vs Unicode strings.&nbsp; Depending on wherever the copy into this memory occurs it could end up copying the Unicode string into a buffer which is sized for ASCII strings.&nbsp; </span></p> 
                        <p style="margin:0px; padding:0px;" > 
                                 </p> 
                        <p style="margin:0px; padding:0px;" > 
                                 </p> 
                        <p class="MsoNormal"> 
                                 </p> 
                        <p style="margin:0px; padding:0px;" > 
                                 </p> 
                        <p style="margin:0px; padding:0px;" > 
                                 </p> 
                        <div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"> 
                                <div> 
                                        <div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"> 
                                                <p class="MsoNormal"> 
                                                        <b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> ironpython-users-bounces+dinov=microsoft.com@python.org [mailto:ironpython-users-bounces+dinov=microsoft.com@python.org] <b>On Behalf Of </b>Markus Schaber<br /> 
                                                        <b>Sent:</b> Sunday, January 22, 2012 11:44 PM<br /> 
                                                        <b>To:</b> Jim Pattee; ironpython-users@python.org<br /> 
                                                        <b>Subject:</b> Re: [Ironpython-users] Memory Allocation in Iron Python</span></p> 
                                                <p style="margin:0px; padding:0px;" > 
                                                         </p> 
                                                <p style="margin:0px; padding:0px;" > 
                                                         </p> 
                                        </div> 
                                </div> 
                                <p class="MsoNormal"> 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                        <span style="font-size:10.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Hi, Jim,</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                        <span style="font-size:10.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">You only gave us half of the source. Which way do you pass the memory address to the native DLL?</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                        <span style="font-size:10.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">One difference is, for example, that .NET relocates objects sometimes, so they need to be pinned.</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                        <span style="font-size:10.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Best regards<br /> 
                                        <br /> 
                                        Markus Schaber<br /> 
                                        -- </span><br /> 
                                        <span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#9C9C9F">___________________________</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="margin-top:6.0pt;mso-margin-bottom-alt:auto"> 
                                        <span style="font-size:9.0pt;font-family:&quot;Arial Black&quot;,&quot;sans-serif&quot;;color:#9C9C9F">We software Automation.</span><br /> 
                                        <br /> 
                                        <span style="font-size:9.0pt;font-family:&quot;Arial Black&quot;,&quot;sans-serif&quot;;color:#C40020">3S-Smart Software Solutions GmbH</span><br /> 
                                        <span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Markus Schaber | Developer<br /> 
                                        Memminger Str. 151 | 87439 Kempten | Germany | Tel. </span><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">+49-831-54031-0 | Fax +49-831-54031-50<br /> 
                                        <br /> 
                                        Email: </span><u><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:blue"><a href="mailto:m.schaber@3s-software.com"><span>m.schaber@3s-software.com</span></a></span></u><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"> | Web: </span><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><a href="http://www.3s-software.com/"><span>http://www.3s-software.com </span></a></span><br /> 
                                        <span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"> CoDeSys internet forum:</span><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><a href="http://forum-en.3s-software.com/"><span> http://forum.3s-software.com</span></a></span><br /> 
                                        <span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"> Download CoDeSys sample projects: </span><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><a href="http://www.3s-software.com/index.shtml?sample_projects"><span>http://www.3s-software.com/index.shtml?sample_projects</span></a></span><br /> 
                                        <br /> 
                                        <i><span style="font-size:7.5pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner</span></i><span style="font-size:7.5pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"> | <i>Trade register: Kempten HRB 6186</i> | <i>Tax ID No.: DE 167014915</i></span><i><span style="color:#1F497D"> </span></i></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                        <b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">Von:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:ironpython-users-bounces+m.schaber=3s-software.com@python.org">ironpython-users-bounces+m.schaber=3s-software.com@python.org</a> <a href="mailto:%5Bmailto:ironpython-users-bounces+m.schaber=3s-software.com@python.org%5D"> [mailto:ironpython-users-bounces+m.schaber=3s-software.com@python.org]</a> <b>Im Auftrag von </b>Jim Pattee<br /> 
                                        <b>Gesendet:</b> Montag, 23. Januar 2012 00:50<br /> 
                                        <b>An:</b> <a href="mailto:ironpython-users@python.org">ironpython-users@python.org</a><br /> 
                                        <b>Betreff:</b> [Ironpython-users] Memory Allocation in Iron Python</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal"> 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> 
                                        <span>I am trying to allocate memory in Iron Python to receive text from a DLL. The allocated memory address is passed to the DLL and the text is copied by the DLL into the memory area. The following code, which works in CPython, is used:</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">allocated <span style="color:teal">=</span> <span style="color:teal">[]</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <b><span style="font-family:Consolas;color:#0000A0">def</span></b><span style="font-family:Consolas"> MemoryAllocation<span style="color:teal">(</span>size<span style="color:teal">):</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">&nbsp;&nbsp;&nbsp;&nbsp; arr_type <span style="color:teal">=</span> c_char <span style="color:teal">*</span> size&nbsp;&nbsp;&nbsp; <span style="color:#316AC5"># create a c_char array</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">&nbsp;&nbsp;&nbsp;&nbsp; arr_obj <span style="color:teal">=</span> arr_type<span style="color:teal">()</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#316AC5"># create an array object</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">&nbsp;&nbsp;&nbsp;&nbsp; allocated<span style="color:blue">.</span>append<span style="color:teal">(</span>arr_obj<span style="color:teal">)</span>&nbsp;&nbsp; <span style="color:#316AC5"># so the object will not be destroyed</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="color:#0000A0">if</span></b> len<span style="color:teal">(</span>allocated<span style="color:teal">)</span> <span style="color:teal">&gt;</span> 1<span style="color:teal">:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#316AC5"> # free memory for the previous object</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="color:#0000A0">del</span></b> allocated<span style="color:teal">[</span>0<span style="color:teal">]</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas">&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="color:#0000A0">return</span></b> addressof<span style="color:teal">(</span>arr_obj<span style="color:teal">)</span>&nbsp;&nbsp; <span style="color:#316AC5"># return a pointer</span></span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="font-family:Consolas;color:#316AC5">&nbsp;</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">When this is used for Iron Python it results in:</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">“Unhandled Exception: System.AccessViolationException: Attempted to read or write</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">protected memory. This is often an indication that other memory is corrupt.”</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">&nbsp;</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">The error results when the memory is copied into Python by the DLL. There are no errors displayed when executing the above code.</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">&nbsp;</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">Why can it not write to the memory? What is the difference in Iron Python and CPython?</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p class="MsoNormal" style="mso-margin-top-alt:auto;text-autospace:none"> 
                                        <span style="color:black">&nbsp;</span></p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                                <p style="margin:0px; padding:0px;" > 
                                         </p> 
                        </div> 
                </div> 
        </div> 
</blockquote> 
<p style="margin:0px; padding:0px;" > 
         </p> 
</span></span>