Skip to content

Commit bc66c55

Browse files
nxtnBillWagner
authored andcommitted
Move P/Invokes to NativeMethods class (#1443)
1 parent 0b0a298 commit bc66c55

File tree

3 files changed

+12
-12
lines changed
  • snippets
    • cpp/VS_Snippets_CLR/conceptual.interop.marshaling/cpp
    • csharp/VS_Snippets_CLR/conceptual.interop.marshaling/cs
    • visualbasic/VS_Snippets_CLR/conceptual.interop.marshaling/vb

3 files changed

+12
-12
lines changed

snippets/cpp/VS_Snippets_CLR/conceptual.interop.marshaling/cpp/systime.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public ref class SystemTime
1616
unsigned short millisecond;
1717
};
1818

19-
public class LibWrap
19+
public class NativeMethods
2020
{
2121
public:
2222
// Declares a managed prototype for the unmanaged function using Platform Invoke.
2323
[DllImport("Kernel32.dll")]
24-
static void GetSystemTime([In,Out] SystemTime^ st);
24+
static void GetSystemTime([In, Out] SystemTime^ st);
2525
};
2626

2727
public class App
@@ -31,9 +31,9 @@ public class App
3131
{
3232
Console::WriteLine("C++/CLI SysTime Sample using Platform Invoke");
3333
SystemTime^ st = gcnew SystemTime();
34-
LibWrap::GetSystemTime(st);
34+
NativeMethods::GetSystemTime(st);
3535
Console::Write("The Date is: ");
36-
Console::Write("{0} {1} {2}", st->month, st->day, st->year);
36+
Console::Write("{0} {1} {2}", st->month, st->day, st->year);
3737
}
3838
};
3939

snippets/csharp/VS_Snippets_CLR/conceptual.interop.marshaling/cs/systime.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class SystemTime
1515
public ushort millisecond;
1616
}
1717

18-
public class LibWrap
18+
internal static class NativeMethods
1919
{
2020
// Declares a managed prototype for the unmanaged function using Platform Invoke.
2121
[DllImport("Kernel32.dll")]
22-
public static extern void GetSystemTime([In, Out] SystemTime st);
22+
internal static extern void GetSystemTime([In, Out] SystemTime st);
2323
}
2424

2525
public class App
@@ -28,9 +28,9 @@ public static void Main()
2828
{
2929
Console.WriteLine("C# SysTime Sample using Platform Invoke");
3030
SystemTime st = new SystemTime();
31-
LibWrap.GetSystemTime(st);
31+
NativeMethods.GetSystemTime(st);
3232
Console.Write("The Date is: ");
33-
Console.Write("{0} {1} {2}", st.month, st.day, st.year);
33+
Console.Write($"{st.month} {st.day} {st.year}");
3434
}
3535
}
3636

snippets/visualbasic/VS_Snippets_CLR/conceptual.interop.marshaling/vb/systime.vb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ Public Class SystemTime
1414
Public millisecond As Short
1515
End Class 'SystemTime
1616

17-
Public Class LibWrap
17+
Friend Class NativeMethods
1818
' Declares a managed prototype for the unmanaged function.
19-
Declare Sub GetSystemTime Lib "Kernel32.dll" (
19+
Friend Declare Sub GetSystemTime Lib "Kernel32.dll" (
2020
<[In](), Out()> ByVal st As SystemTime)
2121
End Class 'LibWrap
2222

2323
Public Class App
2424
Public Shared Sub Main()
2525
Console.WriteLine("VB .NET SysTime Sample using Platform Invoke")
2626
Dim st As New SystemTime()
27-
LibWrap.GetSystemTime(st)
28-
Console.Write("The Date is: {0} {1} {2}", st.month, st.day, st.year)
27+
NativeMethods.GetSystemTime(st)
28+
Console.Write($"The Date is: {st.month} {st.day} {st.year}")
2929
End Sub 'Main
3030
End Class 'App
3131

0 commit comments

Comments
 (0)