WindowsRuntimeMarshal::StringToHString Method (String^)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

This API supports the product infrastructure and is not intended to be used directly from your code.

Allocates a Windows Runtime HSTRING and copies the specified managed string to it.

Namespace:   System.Runtime.InteropServices.WindowsRuntime
Assembly:  mscorlib (in mscorlib.dll)

static IntPtr StringToHString(
	String^ s


Type: System::String^

The managed string to copy.

Return Value

Type: System::IntPtr

An unmanaged pointer to the new HSTRING, or IntPtr::Zero if s is String::Empty.

Exception Condition

The Windows Runtime is not supported on the current version of the operating system.


s is null.

Use the FreeHString method to release the HSTRING when you are done using it.


requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top