[Mono-devel-list] Problem with P/Invoke

Duncan Mak duncan at ximian.com
Sun Feb 1 16:12:46 EST 2004


Hello,

On Sun, 2004-02-01 at 11:58, Jonathan Pryor wrote:
> The runtime is supposed to handle this transparently, so that
> StringBuilder can be used with fixed-with buffers.

I just confirmed this with Jon online,  this bug is not in CVS (0.30)
anymore. Here's the program we used to test:

using System;
using System.Runtime.InteropServices;
using System.Text;

class Test { 
        [DllImport ("libc")]
        static extern IntPtr strncpy (
                StringBuilder dest, string src, uint len);

        static void Main ()
        {
                string src = "test"; 
                uint len = (uint) src.Length;
                StringBuilder dest = new StringBuilder (src.Length);

                for (int i = 0; i < 10; i++) {
                        strncpy (dest, src, len);
                        Console.WriteLine (dest.ToString ());
                }
        }
}

The output is 10x "test".

I don't have time to check whether or not we have this in the test suite
somewhere now, but if we don't, we ought to.

Duncan.



More information about the Mono-devel-list mailing list