Skip to content

Commit 02f4037

Browse files
nxtnRon Petrusha
authored andcommitted
Update PinvokeLib.dll links (#11605)
* Update PinvokeLib.dll links * Update data types link * Enforce coding styles
1 parent 8452ccb commit 02f4037

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
---
22
title: "Marshaling a Delegate as a Callback Method"
33
ms.date: "03/30/2017"
4-
dev_langs:
4+
dev_langs:
55
- "csharp"
66
- "vb"
77
- "cpp"
8-
helpviewer_keywords:
8+
helpviewer_keywords:
99
- "data marshaling, Callback sample"
1010
- "marshaling, Callback sample"
1111
ms.assetid: 6ddd7866-9804-4571-84de-83f5cc017a5a
1212
author: "rpetrusha"
1313
ms.author: "ronpet"
1414
---
1515
# Marshaling a Delegate as a Callback Method
16-
This sample demonstrates how to pass delegates to an unmanaged function expecting function pointers. A delegate is a class that can hold a reference to a method and is equivalent to a type-safe function pointer or a callback function.
17-
16+
This sample demonstrates how to pass delegates to an unmanaged function expecting function pointers. A delegate is a class that can hold a reference to a method and is equivalent to a type-safe function pointer or a callback function.
17+
1818
> [!NOTE]
19-
> When you use a delegate inside a call, the common language runtime protects the delegate from being garbage collected for the duration of that call. However, if the unmanaged function stores the delegate to use after the call completes, you must manually prevent garbage collection until the unmanaged function finishes with the delegate. For more information, see the [HandleRef Sample](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/hc662t8k(v=vs.100)) and [GCHandle Sample](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/44ey4b32(v=vs.100)).
20-
21-
The Callback sample uses the following unmanaged functions, shown with their original function declaration:
22-
23-
- **TestCallBack** exported from PinvokeLib.dll.
24-
25-
```
26-
void TestCallBack(FPTR pf, int value);
27-
```
28-
29-
- **TestCallBack2** exported from PinvokeLib.dll.
30-
31-
```
32-
void TestCallBack2(FPTR2 pf2, char* value);
33-
```
34-
35-
[PinvokeLib.dll](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/as6wyhwt(v=vs.100)) is a custom unmanaged library that contains an implementation for the previously listed functions.
36-
37-
In this sample, the `LibWrap` class contains managed prototypes for the `TestCallBack` and `TestCallBack2` methods. Both methods pass a delegate to a callback function as a parameter. The signature of the delegate must match the signature of the method it references. For example, the `FPtr` and `FPtr2` delegates have signatures that are identical to the `DoSomething` and `DoSomething2` methods.
38-
39-
## Declaring Prototypes
40-
[!code-cpp[Conceptual.Interop.Marshaling#37](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.interop.marshaling/cpp/callback.cpp#37)]
41-
[!code-csharp[Conceptual.Interop.Marshaling#37](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.interop.marshaling/cs/callback.cs#37)]
42-
[!code-vb[Conceptual.Interop.Marshaling#37](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.interop.marshaling/vb/callback.vb#37)]
43-
44-
## Calling Functions
45-
[!code-cpp[Conceptual.Interop.Marshaling#38](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.interop.marshaling/cpp/callback.cpp#38)]
46-
[!code-csharp[Conceptual.Interop.Marshaling#38](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.interop.marshaling/cs/callback.cs#38)]
47-
[!code-vb[Conceptual.Interop.Marshaling#38](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.interop.marshaling/vb/callback.vb#38)]
48-
19+
> When you use a delegate inside a call, the common language runtime protects the delegate from being garbage collected for the duration of that call. However, if the unmanaged function stores the delegate to use after the call completes, you must manually prevent garbage collection until the unmanaged function finishes with the delegate. For more information, see the [HandleRef Sample](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/hc662t8k(v=vs.100)) and [GCHandle Sample](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/44ey4b32(v=vs.100)).
20+
21+
The Callback sample uses the following unmanaged functions, shown with their original function declaration:
22+
23+
- `TestCallBack` exported from PinvokeLib.dll.
24+
25+
```cpp
26+
void TestCallBack(FPTR pf, int value);
27+
```
28+
29+
- `TestCallBack2` exported from PinvokeLib.dll.
30+
31+
```cpp
32+
void TestCallBack2(FPTR2 pf2, char* value);
33+
```
34+
35+
[PinvokeLib.dll](marshaling-data-with-platform-invoke.md#pinvokelibdll) is a custom unmanaged library that contains an implementation for the previously listed functions.
36+
37+
In this sample, the `LibWrap` class contains managed prototypes for the `TestCallBack` and `TestCallBack2` methods. Both methods pass a delegate to a callback function as a parameter. The signature of the delegate must match the signature of the method it references. For example, the `FPtr` and `FPtr2` delegates have signatures that are identical to the `DoSomething` and `DoSomething2` methods.
38+
39+
## Declaring Prototypes
40+
[!code-cpp[Conceptual.Interop.Marshaling#37](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.interop.marshaling/cpp/callback.cpp#37)]
41+
[!code-csharp[Conceptual.Interop.Marshaling#37](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.interop.marshaling/cs/callback.cs#37)]
42+
[!code-vb[Conceptual.Interop.Marshaling#37](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.interop.marshaling/vb/callback.vb#37)]
43+
44+
## Calling Functions
45+
[!code-cpp[Conceptual.Interop.Marshaling#38](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.interop.marshaling/cpp/callback.cpp#38)]
46+
[!code-csharp[Conceptual.Interop.Marshaling#38](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.interop.marshaling/cs/callback.cs#38)]
47+
[!code-vb[Conceptual.Interop.Marshaling#38](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.interop.marshaling/vb/callback.vb#38)]
48+
4949
## See also
5050
- [Miscellaneous Marshaling Samples](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ss9sb93t(v=vs.100))
51-
- [Platform Invoke Data Types](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ac7ay120(v=vs.100))
51+
- [Platform Invoke Data Types](marshaling-data-with-platform-invoke.md#platform-invoke-data-types)
5252
- [Creating Prototypes in Managed Code](creating-prototypes-in-managed-code.md)

docs/framework/interop/marshaling-classes-structures-and-unions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Classes and structures are similar in the .NET Framework. Both can have fields,
6262
void TestArrayInStruct( MYARRAYSTRUCT* pStruct );
6363
```
6464
65-
[PinvokeLib.dll](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/as6wyhwt(v=vs.100)) is a custom unmanaged library that contains implementations for the previously listed functions and four structures: **MYPERSON**, **MYPERSON2**, **MYPERSON3**, and **MYARRAYSTRUCT**. These structures contain the following elements:
65+
[PinvokeLib.dll](marshaling-data-with-platform-invoke.md#pinvokelibdll) is a custom unmanaged library that contains implementations for the previously listed functions and four structures: **MYPERSON**, **MYPERSON2**, **MYPERSON3**, and **MYARRAYSTRUCT**. These structures contain the following elements:
6666
6767
```
6868
typedef struct _MYPERSON
@@ -176,7 +176,7 @@ typedef struct _WIN32_FIND_DATA
176176
void TestUnion(MYUNION u, int type);
177177
```
178178
179-
[PinvokeLib.dll](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/as6wyhwt(v=vs.100)) is a custom unmanaged library that contains an implementation for the previously listed function and two unions, **MYUNION** and **MYUNION2**. The unions contain the following elements:
179+
[PinvokeLib.dll](marshaling-data-with-platform-invoke.md#pinvokelibdll) is a custom unmanaged library that contains an implementation for the previously listed function and two unions, **MYUNION** and **MYUNION2**. The unions contain the following elements:
180180
181181
```
182182
union MYUNION
@@ -248,7 +248,7 @@ typedef struct _SYSTEMTIME {
248248
249249
This sample demonstrates how to call a native function by using the <xref:System.Runtime.InteropServices.Marshal> class and by using unsafe code.
250250
251-
This sample uses a wrapper functions and platform invokes defined in [PinvokeLib.dll](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/as6wyhwt(v=vs.100)), also provided in the source files. It uses the `TestOutArrayOfStructs` function and the `MYSTRSTRUCT2` structure. The structure contains the following elements:
251+
This sample uses a wrapper functions and platform invokes defined in [PinvokeLib.dll](marshaling-data-with-platform-invoke.md#pinvokelibdll), also provided in the source files. It uses the `TestOutArrayOfStructs` function and the `MYSTRSTRUCT2` structure. The structure contains the following elements:
252252
253253
```
254254
typedef struct _MYSTRSTRUCT2

docs/framework/interop/marshaling-different-types-of-arrays.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ An array is a reference type in managed code that contains one or more elements
8080
int TestArrayOfStructs2 (MYPERSON* pPersonArray, int size);
8181
```
8282
83-
[PinvokeLib.dll](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/as6wyhwt(v=vs.100)) is a custom unmanaged library that contains implementations for the previously listed functions and two structure variables, **MYPOINT** and **MYPERSON**. The structures contain the following elements:
83+
[PinvokeLib.dll](marshaling-data-with-platform-invoke.md#pinvokelibdll) is a custom unmanaged library that contains implementations for the previously listed functions and two structure variables, **MYPOINT** and **MYPERSON**. The structures contain the following elements:
8484
8585
```
8686
typedef struct _MYPOINT

0 commit comments

Comments
 (0)