Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 1.32 KB

how-to-specify-an-out-parameter.md

File metadata and controls

51 lines (41 loc) · 1.32 KB
descriptiontitlems.customms.datehelpviewer_keywordsms.assetid
Learn more about: How to: Specify an out parameter
How to: Specify an out parameter
get-started-article
11/04/2016
function parameters
out parameters
02862448-603c-4e9d-a5c5-b45fe38446e3

How to: Specify an out parameter

This sample shows how to specify that a function parameter is an out parameter, and how to call that function from a C# program.

An out parameter is specified in C++ by using xref:System.Runtime.InteropServices.OutAttribute .

Example

The first part of this sample creates a C++ DLL. It defines a type that contains a function with an out parameter.

// cpp_out_param.cpp// compile with: /LD /clrusingnamespaceSystem; public value structTestStruct { staticvoidTest([Runtime::InteropServices::Out] String^ %s) { s = "a string"; } };

This source file is a C# client that consumes the C++ component created in the previous example.

// cpp_out_param_2.cs// compile with: /reference:cpp_out_param.dllusingSystem;classTestClass{publicstaticvoidMain(){Stringt;TestStruct.Test(outt);System.Console.WriteLine(t);}}
a string 

See also

Using C++ Interop (Implicit PInvoke)

close