【开源项目】花密(Flower Password)VB版之Unicode字符转换模块

'*****************************************************************
' Copyright (c) 2011-2012 FlowerPassword.com All rights reserved.
'      Author : xLsDg @ Xiao Lu Software Development Group
'        Blog : http://hi.baidu.com/xlsdg
'          QQ : 4 4 7 4 0 5 7 4 0
'     Version : 1 . 0 . 0 . 0
'        Date : 2 0 1 2 / 0 4 / 0 7
' Description :
'     History :
'*****************************************************************
Option Explicit

Private Declare Function WideCharToMultiByte _
                Lib "kernel32.dll" (ByVal CodePage As Long, _
                                    ByVal dwFlags As Long, _
                                    ByVal lpWideCharStr As Long, _
                                    ByVal cchWideChar As Long, _
                                    ByRef lpMultiByteStr As Any, _
                                    ByVal cchMultiByte As Long, _
                                    ByVal lpDefaultChar As String, _
                                    ByVal lpUsedDefaultChar As Long) As Long

Private Const CP_UTF8 = 65001

Public Function Hash2Byte(ByVal strValue As String) As Byte()

    If Len(strValue) > 0 Then

        Dim bytBuffer(0 To 15) As Byte

        bytBuffer(0) = CByte("&H" + Mid$(strValue, 1, 2))
        bytBuffer(1) = CByte("&H" + Mid$(strValue, 3, 2))
        bytBuffer(2) = CByte("&H" + Mid$(strValue, 5, 2))
        bytBuffer(3) = CByte("&H" + Mid$(strValue, 7, 2))
        bytBuffer(4) = CByte("&H" + Mid$(strValue, 9, 2))
        bytBuffer(5) = CByte("&H" + Mid$(strValue, 11, 2))
        bytBuffer(6) = CByte("&H" + Mid$(strValue, 13, 2))
        bytBuffer(7) = CByte("&H" + Mid$(strValue, 15, 2))
        bytBuffer(8) = CByte("&H" + Mid$(strValue, 17, 2))
        bytBuffer(9) = CByte("&H" + Mid$(strValue, 19, 2))
        bytBuffer(10) = CByte("&H" + Mid$(strValue, 21, 2))
        bytBuffer(11) = CByte("&H" + Mid$(strValue, 23, 2))
        bytBuffer(12) = CByte("&H" + Mid$(strValue, 25, 2))
        bytBuffer(13) = CByte("&H" + Mid$(strValue, 27, 2))
        bytBuffer(14) = CByte("&H" + Mid$(strValue, 29, 2))
        bytBuffer(15) = CByte("&H" + Mid$(strValue, 31, 2))
        Hash2Byte = bytBuffer

    End If

End Function

Public Function UnicodeToUtf8(ByVal UCS As String) As Byte()

    Dim lLength As Long

    lLength = Len(UCS)

    If lLength > 0 Then

        Dim lBufferSize As Long

        Dim lResult     As Long

        Dim abUTF8()    As Byte

        lBufferSize = lLength * 3 + 1
        ReDim abUTF8(lBufferSize - 1)
        lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(UCS), lLength, abUTF8(0), lBufferSize, vbNullString, 0)

        If lResult <> 0 Then
            lResult = lResult - 1
            ReDim Preserve abUTF8(lResult)
            UnicodeToUtf8 = abUTF8

        End If

    End If

End Function


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值