C语言函数声明:
__declspec(dllexport) int __stdcall test1(int a,const char* str);
__declspec(dllexport) void __stdcall test2(unsigned char* buf,int len);
VB.NET调用C语言函数:
'下面这句不能少
Imports System.Runtime.InteropServices
'函数声明,如果是在类中声明,则需要在Function/Sub前加Shared关键字修饰
<DllImport("test.dll", EntryPoint:="test1")>
Public Function test1(ByVal a As Integer, ByVal str As String) As Integer
End Function
<DllImport("test.dll", EntryPoint:="test2")>
Public Sub test2(ByVal buf() As Byte, ByVal len As Integer)
End Sub
'Main函数中调用示例:
Console.WriteLine(test1(123, "张三"))
Dim img() As Byte
img(0)=11
img(1)=12
img(2)=13
test2(img, 3)

这篇博客展示了如何在C语言中声明导出函数,并在VB.NET环境中进行调用。通过使用`__declspec(dllexport)`和`DllImport`特性,实现了跨语言的函数调用。示例包括了整型参数和字符串参数的传递,以及字节数组的处理。
2461

被折叠的 条评论
为什么被折叠?



