Detailed description:
First, declare the unmanaged functions:
[Dllimport ("nativelib. dll", charset = charset. Unicode, callingconvention = callingconvention. cdecl)]
Private extern static void teststringargumentsfixlength (string instring, stringbuilder outstring, int buffersize );
Then select"Enable unmanaged code debugging"
Write as follows:CodeTest:
Private Static void teststringargumentsfixlength ()
{
String instring = "this is a input string .";
Int buffersize = instring. length;
Stringbuilder sb = new stringbuilder (buffersize );
Teststringargumentsfixlength (instring, Sb, buffersize + 1 );
Console. writeline ("Original: {0}", instring );
Console. writeline ("Copied: {0}", SB. tostring ());
}
Click the breakpoint in the red line and pressF11You can step into an unmanaged function.
However, if you modify it:
Private Static void teststringargumentsfixlength ()
{
String instring = "this is a input string .";
Int buffersize = instring. length;
Stringbuilder sb = new stringbuilder (buffersize );
//If the last parameter of the above function call isStringbuilderSpecifies the attributes of an object.
//Although the running result is correct, the debugger
//The Code cannot be executed in a single step. This may be. NET FrameworkSmallBug.
Teststringargumentsfixlength (instring, Sb,SB. Capacity + 1);
Console. writeline ("Original: {0}", instring );
Console. writeline ("Copied: {0}", SB. tostring ());
}
Click the breakpoint in the red line and pressF11In any case, you cannot step into an unmanaged function.
Test environment:
Windows Server 2008
Windows Vista Enterprise
Windows XP SP2
Development tools:
Microsoft Visual maxcompute 2005
Version 8.0.50727.42RTM.050727-4200)
Microsoft. NET Framework
Version 2.0.50727 SP1
YesSource codeIf you try it yourself, please download:
Source code