龙空技术网

VB6NetV2.dll库Get和Post请求支持韩文教程

vb6plus 88

前言:

此刻大家对“net编写dll”大致比较关切,同学们都需要学习一些“net编写dll”的相关资讯。那么小编同时在网络上搜集了一些关于“net编写dll””的相关文章,希望同学们能喜欢,同学们一起来学习一下吧!

1、将VB6NetV2.dll放入工程目录。

如果开发环境提示找不到库,可以放到System32或SysWOW64目录。生产环境没有这个问题。

2、创建mVB6NetV2.bas文件

添加引用声明

Public Declare Function HTTPClient_HEX_Get Lib "VB6NetV2.dll" (ByRef URL As String, Optional ByRef RequestHeaders As String = "", Optional ByRef ResponseHeaders As String = "", Optional ByVal ConnectTimeOut As Integer = 5, Optional ByVal TimeOut As Integer = 60) As String

Public Declare Function HTTPClient_HEX_Post Lib "VB6NetV2.dll" (ByRef URL As String, ByRef HEXPostDatas As String, Optional ByRef RequestHeaders As String = "Content-Type:application/x-www-form-urlencoded", Optional ByRef ResponseHeaders As String = "", Optional ByVal ConnectTimeOut As Integer = 5, Optional ByVal TimeOut As Integer = 60) As String

添加UnicodeToHex函数

Function UnicodeToHex(strSource As String) As String

Dim i As Integer, j As Integer

Dim strText As String

Dim tByte() As Byte

Dim Data() As String

strText = strSource

ReDim Data(Len(strText) * 2)

For i = 1 To Len(strText)

j = (i - 1) * 2

tByte = Mid$(strText, i, 1)

If UBound(tByte) = 1 Then

Data(j) = Hex$(tByte(1))

If Len(Data(j)) = 1 Then Data(j) = "0" & Data(j)

Data(j + 1) = Hex$(tByte(0))

If Len(Data(j + 1)) = 1 Then Data(j + 1) = "0" & Data(j + 1)

Else

Data(j) = "00"

Data(j + 1) = Hex$(tByte(0))

End If

Next

UnicodeToHex = Join(Data, "")

End Function

添加HexToUnicode函数

Public Function HexToUnicode(str As String) As String

Dim i As Integer

Dim tByte() As Byte

Dim intLen As Integer

Dim Data() As String

intLen = Len(str)

ReDim Data(intLen / 4)

For i = 0 To intLen Step 4

ReDim tByte(1)

tByte(0) = Val("&H" & Mid$(str, i + 1 + 2, 2))

tByte(1) = Val("&H" & Mid$(str, i + 1, 2))

Data(i / 4) = tByte

Next

HexToUnicode = Join(Data, "")

End Function

3、添加测试窗体

4、双击[Get测试]按钮,添加代码

Private Sub Command2_Click()

Dim StrHexResult As String

StrHexResult = HTTPClient_HEX_Get(";)

TextBox2.Text = HexToUnicode(StrHexResult)

End Sub

5、双击[Post测试]按钮,添加代码

Private Sub Command1_Click()

Dim StrHexPost As String, StrHexResult As String

StrHexPost = UnicodeToHex(TextBox1.Text)

StrHexResult = HTTPClient_HEX_Post(";, StrHexPost)

TextBox2.Text = HexToUnicode(StrHexResult)

End Sub

6、运行效果

Get测试

Post测试

标签: #net编写dll #vbnet调用dll传值 #dll给vbnet #vbnethttpsget