VB.NET
<DllImport("MyCtesting.dll")> _
Private Shared Sub test(ByRef _IMSS_TEXT As String)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    test(Label1.Text)
End Sub
C++
using boost::lexical_cast;
using boost::bad_lexical_cast;
extern "C"  __declspec(dllexport) void test(std::string &name)
{
    for (int i=0l;i<10;i++)
    {
        name = lexical_cast<string>(i);
    }
}
Why this is throwing error
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Thank in advance.