【问题标题】:How do I properly return a char * from an Unmanaged DLL written in C to VB .net?如何正确地将 char * 从用 C 编写的非托管 DLL 返回到 VB .net?
【发布时间】:2017-01-05 07:56:48
【问题描述】:

如何正确地将非托管 DLL 中的 char * 返回到 VB .net 并将其用作 VB 中的字符串? 从a similar post for C# and C++看来,做这种事情的c#语法是

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

VB .net 有对应的语法吗?

【问题讨论】:

    标签: .net c vb.net interop unmanaged


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

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 2019-07-19
      • 2010-11-02
      • 1970-01-01
      • 2012-04-28
      • 2018-03-08
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多