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

问题描述 投票:1回答:1

我很迷茫,是个新手,所以请多多包涵。

在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中做到这一点?甚至可以做到吗?

c++ vb.net function dll replication
1个回答
0
投票
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。

© www.soinside.com 2019 - 2024. All rights reserved.