Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

lstrcpy (kernel32)
 
.
Summary
The lstrcpyn API
Summary
The lstrcpy API

C# Signature:

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

User-Defined Types:

None.

    string lpString2);

Notes:

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

Alternate definition (useful when dealing with buffer pointers):

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

Tips & Tricks:

Please add some!

VB.NET Signature:

<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function lstrcpy(<Out> lpString1 As StringBuilder, lpString2 As String) As IntPtr
End Function

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!

User-Defined Types:

None.

Documentation
lstrcpyn on MSDN

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
lstrcpy on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions