@@ -23,6 +23,7 @@ private class EntryPoints
23
23
24
24
private const string UShortSuffix = "_ushort" ;
25
25
private const string ByteSuffix = "_byte" ;
26
+ private const string BStrSuffix = "_bstr" ;
26
27
27
28
public class Byte
28
29
{
@@ -41,6 +42,15 @@ public class UShort
41
42
public const string ReverseInplace = EntryPoints . ReverseInplace + UShortSuffix ;
42
43
public const string ReverseReplace = EntryPoints . ReverseReplace + UShortSuffix ;
43
44
}
45
+
46
+ public class BStr
47
+ {
48
+ public const string ReturnLength = EntryPoints . ReturnLength + BStrSuffix ;
49
+ public const string ReverseReturn = EntryPoints . ReverseReturn + BStrSuffix ;
50
+ public const string ReverseOut = EntryPoints . ReverseOut + BStrSuffix ;
51
+ public const string ReverseInplace = EntryPoints . ReverseInplace + BStrSuffix ;
52
+ public const string ReverseReplace = EntryPoints . ReverseReplace + BStrSuffix ;
53
+ }
44
54
}
45
55
46
56
public partial class Utf16
@@ -185,6 +195,31 @@ public partial class LPStr
185
195
public static partial void Reverse_Replace_Ref ( [ MarshalAs ( UnmanagedType . LPStr ) ] ref string s ) ;
186
196
}
187
197
198
+ public partial class BStr
199
+ {
200
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReturnLength ) ]
201
+ public static partial int ReturnLength ( [ MarshalAs ( UnmanagedType . BStr ) ] string s ) ;
202
+
203
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReturnLength , StringMarshalling = StringMarshalling . Utf16 ) ]
204
+ public static partial int ReturnLength_IgnoreStringMarshalling ( [ MarshalAs ( UnmanagedType . BStr ) ] string s ) ;
205
+
206
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReverseReturn ) ]
207
+ [ return : MarshalAs ( UnmanagedType . BStr ) ]
208
+ public static partial string Reverse_Return ( [ MarshalAs ( UnmanagedType . BStr ) ] string s ) ;
209
+
210
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReverseOut ) ]
211
+ public static partial void Reverse_Out ( [ MarshalAs ( UnmanagedType . BStr ) ] string s , [ MarshalAs ( UnmanagedType . BStr ) ] out string ret ) ;
212
+
213
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReverseInplace ) ]
214
+ public static partial void Reverse_Ref ( [ MarshalAs ( UnmanagedType . BStr ) ] ref string s ) ;
215
+
216
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReverseInplace ) ]
217
+ public static partial void Reverse_In ( [ MarshalAs ( UnmanagedType . BStr ) ] in string s ) ;
218
+
219
+ [ LibraryImport ( NativeExportsNE_Binary , EntryPoint = EntryPoints . BStr . ReverseReplace ) ]
220
+ public static partial void Reverse_Replace_Ref ( [ MarshalAs ( UnmanagedType . BStr ) ] ref string s ) ;
221
+ }
222
+
188
223
public partial class StringMarshallingCustomType
189
224
{
190
225
public partial class Utf16
@@ -418,6 +453,48 @@ public void AnsiStringByRef(string value)
418
453
Assert . Equal ( expected , refValue ) ;
419
454
}
420
455
456
+ [ Theory ]
457
+ [ MemberData ( nameof ( UnicodeStrings ) ) ]
458
+ public void BStrStringMarshalledAsExpected ( string value )
459
+ {
460
+ int expectedLen = value != null ? value . Length : - 1 ;
461
+
462
+ Assert . Equal ( expectedLen , NativeExportsNE . BStr . ReturnLength ( value ) ) ;
463
+ Assert . Equal ( expectedLen , NativeExportsNE . BStr . ReturnLength_IgnoreStringMarshalling ( value ) ) ;
464
+ }
465
+
466
+ [ Theory ]
467
+ [ MemberData ( nameof ( UnicodeStrings ) ) ]
468
+ public void BStrStringReturn ( string value )
469
+ {
470
+ string expected = ReverseChars ( value ) ;
471
+
472
+ Assert . Equal ( expected , NativeExportsNE . BStr . Reverse_Return ( value ) ) ;
473
+
474
+ string ret ;
475
+ NativeExportsNE . BStr . Reverse_Out ( value , out ret ) ;
476
+ Assert . Equal ( expected , ret ) ;
477
+ }
478
+
479
+ [ Theory ]
480
+ [ MemberData ( nameof ( UnicodeStrings ) ) ]
481
+ public void BStrStringByRef ( string value )
482
+ {
483
+ string refValue = value ;
484
+ string expected = ReverseChars ( value ) ;
485
+
486
+ NativeExportsNE . BStr . Reverse_In ( in refValue ) ;
487
+ Assert . Equal ( value , refValue ) ; // Should not be updated when using 'in'
488
+
489
+ refValue = value ;
490
+ NativeExportsNE . BStr . Reverse_Ref ( ref refValue ) ;
491
+ Assert . Equal ( expected , refValue ) ;
492
+
493
+ refValue = value ;
494
+ NativeExportsNE . BStr . Reverse_Replace_Ref ( ref refValue ) ;
495
+ Assert . Equal ( expected , refValue ) ;
496
+ }
497
+
421
498
[ Theory ]
422
499
[ MemberData ( nameof ( UnicodeStrings ) ) ]
423
500
public void StringMarshallingCustomType_MarshalledAsExpected ( string value )
0 commit comments