PInvoking with StringBuilder in a Unit Test
问题 I have a C DLL I am PInvoking. The main goal is to get back a GUID string of 39 characters, such as abcd-abcd-abcd-abcd-abcd-abcd-abcd-abcd . I first call one method to get the size of this string, which I expect to be 39 characters, and then I call another function passing it a StringBuilder with a capacity of 39: [DllImport("test.dll")] public static extern int get_size(); [DllImport("test.dll")] public static extern void get_string(StringBuilder result); My code looks something like this: