简体   繁体   中英

How do I properly return a char * from an Unmanaged DLL written in C to VB .net?

How do I properly return a char * from an Unmanaged DLL to VB .net and use it as a string in VB? From a similar post for C# and C++ it appears that the c# syntax to do such a thing is

[DllImport("api.dll")]
[return : MarshalAs(UnmanagedType.LPStr)]
internal static extern string errMessage(int err);
...
string message = errMessage(err);

Does VB .net have a corresponding syntax?

<DllImport("Project1.dll", SetLastError:=True, CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)>
Function agmemwrite(graph As IntPtr) As <MarshalAs(UnmanagedType.LPStr)> String
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM