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 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 /clr
using namespace System;
public value struct TestStruct {
static void Test([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.dll
using System;
class TestClass {
public static void Main() {
String t;
TestStruct.Test(out t);
System.Console.WriteLine(t);
}
}
a string
See also
Tilbakemeldinger
https://aka.ms/ContentUserFeedback.
Kommer snart: Gjennom 2024 faser vi ut GitHub Issues som tilbakemeldingsmekanisme for innhold, og erstatter det med et nytt system for tilbakemeldinger. Hvis du vil ha mer informasjon, kan du se:Send inn og vis tilbakemelding for