File tree Expand file tree Collapse file tree
examples/call-native-function Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using System ;
22using System . Runtime . InteropServices ;
3+ using System . Runtime . Versioning ;
34using System . Text ;
45
56namespace ExampleProject {
@@ -11,12 +12,14 @@ public static unsafe int IndirectIncrement1(int n) {
1112 return rusty_increment ( n ) ;
1213 }
1314
15+ [ SupportedOSPlatform ( "windows" ) ]
1416 [ UnmanagedCallersOnly ]
1517 public static int IndirectIncrement2 ( int n ) {
1618 return rusty_increment ( n ) ;
1719 }
1820
19- [ DllImport ( "call-native-function.exe" ) ]
21+ [ SupportedOSPlatform ( "windows" ) ]
22+ [ DllImport ( "call-native-function.exe" , ExactSpelling = true ) ]
2023 public static extern int rusty_increment ( int n ) ;
2124 }
2225}
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ fn main() {
2323 pdcstr ! ( "IndirectIncrement1" ) ,
2424 )
2525 . unwrap ( ) ;
26+ #[ cfg( windows) ]
2627 let increment2 = delegate_loader
2728 . get_function_with_unmanaged_callers_only :: < fn ( i32 ) -> i32 > (
2829 pdcstr ! ( "ExampleProject.Program, ExampleProject" ) ,
@@ -31,5 +32,6 @@ fn main() {
3132 . unwrap ( ) ;
3233
3334 assert_eq ! ( 2 , increment1( 1 ) ) ;
35+ #[ cfg( windows) ]
3436 assert_eq ! ( 3 , increment2( 2 ) ) ;
3537}
You can’t perform that action at this time.
0 commit comments