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

loadstring (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int LoadString(IntPtr hInstance, uint uID,StringBuilder lpBuffer, int nBufferMax);

VB.Net Signature:

<DllImport("User32", SetLastError:=True)> _
Public Shared Function LoadString(ByVal hInstance As IntPtr, ByVal uID As UInt32, ByVal lpBuffer As Text.StringBuilder, ByVal nBufferMax As Integer) As Integer
End Function

User-Defined Types:

None.

Notes:

IMPORTANT
Add CharSet = CharSet.Auto otherwise it will replace all non-latin characters with ????

http://msdn.microsoft.com/en-us/library/7b93s42f.aspx

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpcondefaultmarshalingforstrings.htm

suggests that a StringBuilder be used instead of a string type as was listed previously.

Tips & Tricks:

Please add some!

Sample Code:

using System.Text;
public String GetStringResource(IntPtr hModuleInstance, uint uiStringID)
{
    StringBuilder sb = new StringBuilder(255);
    LoadString(hModuleInstance, uiStringID, sb, sb.Capacity + 1);
    return sb.ToString();
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
LoadString 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