Article ID: 321078 - Last Review: February 12, 2007 - Revision: 2.4 A string that you pass to an unmanaged Win32 API in Visual Studio .NET or in Visual Studio 2005 returns emptyThis article was previously published under Q321078 On This PageSYMPTOMS
When you pass a String data type variable to a Win32 application programming interface (API) as an out parameter, the string that the Win32 function call returns does not change.
CAUSE
This problem occurs because you cannot modify Visual Basic .NET, Visual Basic 2005, and Visual C# strings. By default, you cannot change the String class after the String class is created. For more information about the String class, see the "References" section.
RESOLUTION
If you send a string to a Win32 API function, and if the function modifies or populates the string, use the StringBuilder class instead of the String data type. For example, the following code samples demonstrate how to use the StringBuilder class with an out parameter of a Win32 API function call. Visual Basic .NET or Visual Basic 2005 Console Application Sample
Visual C# .NET or Visual C# 2005 Console Application Sample
REFERENCES
For more information about the String and the StringBuilder classes, visit the following MSDN Web sites:
String Class http://msdn.microsoft.com/en-us/library/system.string(VS.71).aspx (http://msdn.microsoft.com/en-us/library/system.string(VS.71).aspx) StringBuilder Class http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(VS.71).aspx (http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(VS.71).aspx) APPLIES TO
| Article Translations
|

Back to the top
