Skip to content

Commit 66775a5

Browse files
nxtnRon Petrusha
authored andcommitted
Move P/Invokes to NativeMethods class (#1567)
1 parent 57c4233 commit 66775a5

File tree

3 files changed

+21
-24
lines changed
  • snippets
    • cpp/VS_Snippets_CLR/Interop InOutParameters/CPP
    • csharp/VS_Snippets_CLR/Interop InOutParameters/CS
    • visualbasic/VS_Snippets_CLR/Interop InOutParameters/VB

3 files changed

+21
-24
lines changed

snippets/cpp/VS_Snippets_CLR/Interop InOutParameters/CPP/inout.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,26 @@
33
using namespace System;
44
using namespace System::Runtime::InteropServices;
55

6-
76
// Declare a class member for each structure element.
87

9-
[StructLayout(LayoutKind::Sequential,CharSet=CharSet::Unicode)]
8+
[StructLayout(LayoutKind::Sequential, CharSet = CharSet::Unicode)]
109
public ref class OpenFileName
1110
{
1211
public:
13-
int structSize;
14-
String^ filter;
15-
String^ file;
16-
// ...
12+
int structSize;
13+
String^ filter;
14+
String^ file;
15+
// ...
1716
};
1817

19-
public ref class LibWrap
18+
private ref class NativeMethods
2019
{
2120
public:
2221

23-
// Declare a managed prototype for the unmanaged function.
22+
// Declare a managed prototype for the unmanaged function.
2423

25-
[DllImport("Comdlg32.dll",CharSet=CharSet::Unicode)]
26-
static bool GetOpenFileName( [In,Out]OpenFileName^ ofn );
24+
[DllImport("Comdlg32.dll", CharSet = CharSet::Unicode)]
25+
static bool GetOpenFileName([In, Out]OpenFileName^ ofn);
2726
};
2827

2928
void main() {}

snippets/csharp/VS_Snippets_CLR/Interop InOutParameters/CS/inout.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ public class OpenFileName
1313
// ...
1414
}
1515

16-
public class LibWrap
16+
internal static class NativeMethods
1717
{
1818
// Declare a managed prototype for the unmanaged function.
1919
[DllImport("Comdlg32.dll", CharSet = CharSet.Unicode)]
20-
public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
20+
internal static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
2121
}
2222

2323
public class MainMethod
2424
{
2525
static void Main()
2626
{ }
27-
2827
}
2928
// </Snippet1>
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
' <Snippet1>
22
Imports System.Runtime.InteropServices
33

4-
54
' Declare a class member for each structure element.
6-
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
5+
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
76
Public Class OpenFileName
87

9-
Public structSize As Integer = 0
10-
Public filter As String = Nothing
11-
Public file As String = Nothing
12-
' ...
8+
Public structSize As Integer = 0
9+
Public filter As String = Nothing
10+
Public file As String = Nothing
11+
' ...
1312

1413
End Class
1514

16-
Public Class LibWrap
17-
' Declare managed prototype for the unmanaged function.
18-
Declare Unicode Function GetOpenFileName Lib "Comdlg32.dll" ( _
19-
<[In](), Out()> ByVal ofn As OpenFileName) As Boolean
15+
Friend Class NativeMethods
16+
' Declare managed prototype for the unmanaged function.
17+
Friend Declare Unicode Function GetOpenFileName Lib "Comdlg32.dll" (
18+
<[In](), Out()> ByVal ofn As OpenFileName) As Boolean
2019
End Class
2120

2221
Public Class App
@@ -25,4 +24,4 @@ Public Class App
2524
End Sub
2625
End Class
2726

28-
' </Snippet1>
27+
' </Snippet1>

0 commit comments

Comments
 (0)