[Mono-devel-list] Problem with P/Invoke
Carlos Alberto Cortez Guevara
carlos at unixmexico.org
Fri Jan 30 14:16:55 EST 2004
Hi,
I was playing with some P/Invoke samples, and I found that the next code
doesn't work perfect.
I'm loading the strncpy function from the standard library (libc), and
the first call works perfect. However, in the second call (and third,
..) it doesn't work.
Is this a bug?
Regards,
Carlos.
--
--------------------------------------------------
/* The definition of myself */
using Cortez;
using GeniusIntelligence;
public class Carlos : Human, IGenius, ILinuxUser {
static void Main () {
Me.Think();
}
}
--------------------------------------------------
-------------- next part --------------
//
// P/Invoke Sample
//
//
using System;
using System.Runtime.InteropServices;
using System.Text;
public class Sample {
[DllImport ("libc")]
private static extern string strncpy (StringBuilder dest, string src, int length);
public static void Main ()
{
StringBuilder sb = new StringBuilder (50);
string src = "This message should be printed";
for (int i = 1; i <= src.Length; i++) {
strncpy (sb, src, i);
Console.WriteLine (sb);
}
}
}
More information about the Mono-devel-list
mailing list