VB.NET DLL 中的 C++ DLL 函数复制

C++ DLL function replication in VB.NET DLL

我很迷茫,我是新手,所以请耐心等待。

在 C++ 中,函数看起来像这样:

int __stdcall helloworld(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause) {
    strcpy(data, "hello world");
    return 3;
}

我正试图在 VB.NET 中复制它,但我在 char *datachar *parms 部分遇到了一个小问题。

Public Shared Function helloworld(ByVal mWnd As IntPtr, ByVal aWnd As IntPtr, ByRef data As Char, ByRef parms As Char, ByVal show As Boolean, ByVal nopause As Boolean) As Integer
    data = "hello world"
    Return 3
End Function

这导致了 "h" 的输出,所以我尝试了 data(),这导致了乱码。然后我在某处读到 VB.NET 中的 C/C++ char 等价物是字节,所以我尝试了 data() As Bytedata = System.Text.Encoding.Default.GetBytes("hello world"),结果再次出现乱码。

DLL接收到的东西是不能改变的,所以我需要想办法让VB.NET处理。我的问题是;我如何在 VB.NET 中执行此操作?甚至可以做到吗?

经过一些密集的按钮粉碎后,由于 Visual Vincent 的 StringBuilder 建议,我设法做到了:

Imports System.Runtime.InteropServices
Imports System.Text
Public Class MyClass
    <DllExport(CallingConvention.StdCall)>
    Public Shared Function helloworld(ByVal mWnd As IntPtr, ByVal aWnd As IntPtr, ByVal data As StringBuilder, ByVal parms As StringBuilder, ByVal show As Boolean, ByVal nopause As Boolean) As Integer
        data.Append("hello world")
        Return 3
    End Function
End Class

也将 ByRef 更改为 ByVal。