Skip to content

Commit f79c38d

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

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
21
// <Snippet1>
32
using namespace System;
43
using namespace System::Runtime::InteropServices;
5-
public ref class LibWrap
4+
5+
private ref class NativeMethods
66
{
77
public:
88

9-
// CallingConvention.Cdecl must be used since the stack is
10-
// cleaned up by the caller.
11-
// int printf( const char *format [, argument]... )
9+
// CallingConvention.Cdecl must be used since the stack is
10+
// cleaned up by the caller.
11+
// int printf( const char *format [, argument]... )
1212

13-
[DllImport("msvcrt.dll",CharSet=CharSet::Unicode, CallingConvention=CallingConvention::Cdecl)]
14-
static int printf( String^ format, int i, double d );
13+
[DllImport("msvcrt.dll", CharSet = CharSet::Unicode, CallingConvention = CallingConvention::Cdecl)]
14+
static int printf(String^ format, int i, double d);
1515

16-
[DllImport("msvcrt.dll",CharSet=CharSet::Unicode, CallingConvention=CallingConvention::Cdecl)]
17-
static int printf( String^ format, int i, String^ s );
16+
[DllImport("msvcrt.dll", CharSet = CharSet::Unicode, CallingConvention = CallingConvention::Cdecl)]
17+
static int printf(String^ format, int i, String^ s);
1818
};
1919

2020
int main()
2121
{
22-
LibWrap::printf( "\nPrint params: %i %f", 99, 99.99 );
23-
LibWrap::printf( "\nPrint params: %i %s", 99, "abcd" );
22+
NativeMethods::printf("\nPrint params: %i %f", 99, 99.99);
23+
NativeMethods::printf("\nPrint params: %i %s", 99, "abcd");
2424
}
25-
2625
// </Snippet1>

snippets/visualbasic/VS_Snippets_CLR/Interop CallingConvention/VB/callingconv.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
' <Snippet1>
22
Imports System.Runtime.InteropServices
33

4-
Friend Class LibWrap
4+
Friend Class NativeMethods
55
' Visual Basic does not support varargs, so all arguments must be
66
' explicitly defined. CallingConvention.Cdecl must be used since the stack
77
' is cleaned up by the caller.
@@ -20,8 +20,8 @@ End Class
2020

2121
Public Class App
2222
Public Shared Sub Main()
23-
LibWrap.printf(ControlChars.CrLf + "Print params: %i %f", 99, 99.99)
24-
LibWrap.printf(ControlChars.CrLf + "Print params: %i %s", 99, "abcd")
23+
NativeMethods.printf(ControlChars.CrLf + "Print params: %i %f", 99, 99.99)
24+
NativeMethods.printf(ControlChars.CrLf + "Print params: %i %s", 99, "abcd")
2525
End Sub
2626
End Class
2727
' </Snippet1>

0 commit comments

Comments
 (0)