lstrcpy (kernel32)
Last changed: -104.180.240.187

.
Summary
The lstrcpyn API

C# Signature:

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern IntPtr lstrcpyn(
    [Out] StringBuilder lpString1,
    string lpString2,
    int iMaxLength);

User-Defined Types:

None.

Notes:

For those having trouble with StringBuilder, the below sample code uses the alternative IntPtr method.

Tips & Tricks:

Please add some!

Sample Code:

C#

[DllImport("kernel32", CharSet = CharSet.Auto)]
static extern IntPtr lstrcpyn(IntPtr dest, IntPtr src, int len);

void FillABuffer(IntPtr dest, int dest_maxlen, string source)
{
   IntPtr tmp_ptr = Marshal.StringToHGlobalAuto(source);
   lstrcpyn(dest, tmp_ptr, dest_maxlen);
   Marshal.FreeHGlobal(tmp_ptr);
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
lstrcpyn on MSDN