vb.net调用C++ 的dll,字符串传递

用VB.net调用我自己写的异步多线程socket库发送数据,作为物联网设备上应用。

Public Class Form1
    Private Declare Function CommStackInit Lib "EasyAsyncStack.dll" (ByVal a As Integer, ByVal b As Integer) As Integer
    Private Declare Function ES_ConnToServer Lib "EasyAsyncStack.dll" (ByVal ip As String, ByVal b As Integer) As Integer
    Private Declare Function SendCollectorText Lib "EasyAsyncStack.dll" (ByVal handle As Integer, ByVal value As String, ByVal len As Integer) As Integer

    Dim m_iSocketHandle As Integer
    'SendCollectorText(long dwKeyAdpHandler, char* pMsgData, short sDataLen)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 连接服务器.Click
        Dim res As Integer

        res = CommStackInit(10, 100)
        m_iSocketHandle = ES_ConnToServer("127.0.0.1", 8090)
        'SendCollectorText(m_iSocketHandle, "xiaoyu@998", strlen("xiaoyu@998"));
        SendCollectorText(m_iSocketHandle, "xiaoyu@999", 10)
        SendCollectorText(m_iSocketHandle, "this is a text", Len("this is a text"))
        '这里长度要指定要发送的字符串的真实长度
        SendCollectorText(m_iSocketHandle, "19中国长城1000", 20)
        SendCollectorText(m_iSocketHandle, "中国长城2002", 20)
        SendCollectorText(m_iSocketHandle, "中国长城8008", 20)

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SendCollectorText(m_iSocketHandle, "那是一个好消息@@88", 28)
    End Sub
End Class
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值