char* to a string in C#

后端 未结 4 1882
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-14 20:14

I\'m calling a function from a native DLL which returns a char* pointer, how can I convert the returned pointer to a string ? I tried :

char* c = f         


        
4条回答
  •  北海茫月
    2021-02-14 20:32

    Perhaps the native DLL is actually returning an ANSI string instead of a Unicode string. In that case, call Marshal.PtrToStringAnsi:

    using System.Runtime.InteropServices;
    ...
    string s = Marshal.PtrToStringAnsi((IntPtr)c);
    

提交回复
热议问题