Global It Leader!!



 
 

VB 멀티바이트 형식을 유니코드 형식으로 바꿔주는 함수

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 4,800회 작성일 13-12-17 09:35

본문

Private Declare Function MultiByteToWideChar Lib "Kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "Kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function GetACP Lib "Kernel32" () As Long
Private Const CP_ACP = 0 ' default to ANSI code page
Private Const CP_UTF8 = 65001 ' default to UTF-8 code page
'--------------------------------
' AToW
'
' ANSI to UNICODE conversion, via a given codepage.
'--------------------------------
Public Function AToW(ByVal st As String, Optional ByVal cpg As Long = -1, Optional ByVal lFlags As Long = 0) As String
  Dim stBuffer As String
  Dim cwch As Long
  Dim pwz As Long
  Dim pwzBuffer As Long
  If cpg = -1 Then cpg = GetACP()
  pwz = StrPtr(st)
  cwch = MultiByteToWideChar(cpg, lFlags, pwz, -1, 0&, 0&)
  stBuffer = String$(cwch + 1, vbNullChar)
  pwzBuffer = StrPtr(stBuffer)
  cwch = MultiByteToWideChar(cpg, lFlags, pwz, -1, pwzBuffer, Len(stBuffer))
  AToW = Left$(stBuffer, cwch - 1)
End Function
'--------------------------------
' WToA
'
' UNICODE to ANSI conversion, via a given codepage
'--------------------------------
Public Function WToA(ByVal st As String, Optional ByVal cpg As Long = -1, Optional ByVal lFlags As Long = 0) As String
  Dim stBuffer As String
  Dim cwch As Long
  Dim pwz As Long
  Dim pwzBuffer As Long
  Dim lpUsedDefaultChar As Long
  If cpg = -1 Then cpg = GetACP()
  pwz = StrPtr(st)
  cwch = WideCharToMultiByte(cpg, lFlags, pwz, -1, 0&, 0&, ByVal 0&, ByVal 0&)
  stBuffer = String$(cwch + 1, vbNullChar)
  pwzBuffer = StrPtr(stBuffer)
  cwch = WideCharToMultiByte(cpg, lFlags, pwz, -1, pwzBuffer, Len(stBuffer), ByVal 0&, ByVal 0&)
  WToA = Left$(stBuffer, cwch - 1)
End Function
'Use this to encode before you send...
Function EncodeUTF8(ByVal cnvUni As String)
  If cnvUni = vbNullString Then Exit Function
  EncodeUTF8 = WToA(cnvUni, CP_UTF8, 0)
End Function
'Use this to decode received strings...
Function DecodeUTF8(ByVal cnvUni As String)
  If cnvUni = vbNullString Then Exit Function
  cnvUni = WToA(cnvUni, CP_ACP)
  DecodeUTF8 = AToW(cnvUni, CP_UTF8)
End Function
 
 

댓글목록

등록된 댓글이 없습니다.

전체 95
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
75 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4578 02-17
74 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7127 02-17
73 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4641 02-11
72 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4717 02-11
71 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4590 02-07
70 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4365 08-04
69 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4531 12-25
68 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11652 12-25
67 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5492 12-24
66 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4935 12-24
65 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5170 12-20
64 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4986 12-20
63 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6363 12-20
62 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4984 12-20
61 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10355 12-19
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4801 12-17
59 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6846 12-17
58 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4700 12-16
57 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4445 12-16
56 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4591 12-16