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 *data
和char *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++字符等价物是字节,所以我尝试了data() As Byte
和data = 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。
相关文章:
- 使用 memcpy 函数C++复制字符数组
- 使用复制构造函数复制双精度数组
- VB.NET DLL中的C++DLL函数复制
- 使用SSE内部函数复制少量数据时出现问题
- 不可变的 lambda 函数:复制捕获的变量是否允许是 const
- C 无可行的构造函数复制类型的变量
- 没有可行的构造函数复制类型 'MyString' 的数组元素
- 编译时,复制构造函数/复制分配和正常功能调用优化之间是否存在任何区别
- 将具有默认参数的lambda函数复制到变量
- 如何最小化调用列表构造函数(复制构造函数)的次数?
- C 11矢量构造函数复制与范围
- std::函数复制运算符 (MSVC2012) 的奇怪行为
- 从函数复制成本返回STL向量
- 我定义了一个非复制构造函数;复制构造函数还会被隐式定义吗
- 可以将构造函数复制为转换运算符
- 标准::函数复制参数
- C++:strcpy 函数复制空值
- 将基类指针的构造函数复制到子类
- Zlib解压缩函数复制而不是解压缩
- C++树类:构造函数/复制/内存泄漏