📄 bastranslate.bas
字号:
Attribute VB_Name = "basTranslate"
' C2VB Converts C style definitions to VB
' Copyright (C) 2000 Kimon Andreou (kimon@mindless.com)
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Option Explicit
Option Base 0
Public IsPublic As Boolean
Public LibraryName As String
Public Const vbTab As String = " "
'Splits a string into tokens based on the delimiter specified
'strString: The source string
'TokenID: The token wanted from the string
'Token: The token returned
'Delimiter: The delimiter to use (default is " ")
'returns an array of strings where each item is a token
Public Function GetToken(strString As String, TokenID As Integer, Token As String, Optional Delimiter As String = " ") As Variant
Dim Tokens() As String
Dim UpperLimit As Integer
Tokens = Split(strString, Delimiter)
UpperLimit = UBound(Tokens)
If UpperLimit = -1 Then
Token = ""
GetToken = Tokens
Exit Function
End If
If TokenID > UpperLimit Then
Token = Tokens(UpperLimit)
GetToken = Tokens
Else
GetToken = Tokens
Token = Tokens(TokenID)
End If
End Function
'Joins an array of strings with a delimiter
'I wrote this in case I wanted to add functionality not available with Join()
Public Function ConcatString(strStrings() As String, Optional Delimiter As String = " ") As String
Dim cnt As Integer
If UBound(strStrings) = 0 Then
ConcatString = strStrings(0)
Exit Function
End If
For cnt = 0 To UBound(strStrings) - 1
ConcatString = ConcatString & strStrings(cnt) & Delimiter
Next cnt
ConcatString = ConcatString & strStrings(UBound(strStrings))
End Function
'Adds spaces around "," "(" ")"
Public Function AddSpaces(strString As String) As String
Dim dummy1 As String
Dim dummy2 As String
Dim strArray() As String
strArray = GetToken(strString, 1, dummy1, "(")
dummy1 = ConcatString(strArray, " ( ")
strArray = GetToken(dummy1, 1, dummy2, ",")
dummy1 = ConcatString(strArray, " , ")
strArray = GetToken(dummy1, 1, dummy2, ")")
dummy1 = ConcatString(strArray, " ) ")
AddSpaces = dummy1
End Function
'Determines what is the VB equivalent data type
'If it cannot figure it out, it returns the C name (useful for UDTs)
'Also determines if it is an array or a pointer (ByRef)
'and if it is a function or a procedure
Public Function GetType(strArray() As String, Optional IsProcedure As Boolean, Optional IsByVal As Boolean, Optional IsArray As Boolean) As String
Dim Ctype As String
Dim Types() As String
Dim dummy As String
Dim cnt As Integer
'Get rid of in-between spaces
For cnt = 0 To UBound(strArray)
strArray(cnt) = Trim(strArray(cnt))
Ctype = Ctype & strArray(cnt) & IIf(Len(strArray(cnt)) = 0, "", " ")
Next cnt
Types = GetToken(Trim(Ctype), 0, dummy)
Ctype = Join(Types, " ")
IsProcedure = False
IsByVal = True
'Check if we should pass ByRef or not and whether it is an array
If InStr(Ctype, "*") <> 0 Then IsByVal = False
If InStr(Ctype, "**") <> 0 Then IsArray = True
If InStr(Ctype, "[") <> 0 Then
IsByVal = False
IsArray = True
End If
If InStr(Ctype, "const") <> 0 Then
IsByVal = True
Ctype = Trim(RemoveChar(Ctype, "const"))
End If
If InStr(Ctype, "CONST") <> 0 Then
IsByVal = True
Ctype = Trim(RemoveChar(Ctype, "CONST"))
End If
If Left(Ctype, 2) = "LP" Then IsByVal = False
'Get rid of "*", "[", "]", "WINAPI", "CALLBACK"
Ctype = Trim(RemoveChar(Ctype, "*"))
Ctype = Trim(RemoveChar(Ctype, "["))
Ctype = Trim(RemoveChar(Ctype, "]"))
Ctype = Trim(RemoveChar(Ctype, "WINAPI"))
Ctype = Trim(RemoveChar(Ctype, "CALLBACK"))
'This is where the actual checking happens
'maybe saving this in an external file would be be better...
'i'll have to think about it
Select Case Ctype
Case "int":
GetType = "Long"
Case "time_t":
GetType = "Long"
Case "size_t":
GetType = "Long"
Case "unsigned int":
GetType = "Long"
Case "unsigned char":
GetType = "Byte"
Case "void":
IsProcedure = True
GetType = ""
Case "VOID":
IsProcedure = True
GetType = ""
Case "char":
GetType = IIf((Not IsByVal) Or IsArray, "String", "Byte")
Case "ATOM":
GetType = "Long"
Case "BOOL":
GetType = "Long"
Case "BOOLEAN":
GetType = "Long"
Case "BYTE":
GetType = "Byte"
Case "CHAR":
GetType = "Byte"
Case "COLORREF":
GetType = "Long"
Case "CRITICAL_SECTION":
GetType = "Long"
Case "CTRYID":
GetType = "Long"
Case "DWORD":
GetType = "Long"
Case "DWORD_PTR":
GetType = "Double"
Case "DWORD32":
GetType = "Long"
Case "DWORD64":
GetType = "Currency"
Case "FLOAT":
GetType = "Double"
Case "FILE_SEGMENT_ELEMENT":
GetType = "Currency"
Case "HACCEL":
GetType = "Long"
Case "HANDLE":
GetType = "Long"
Case "HBITMAP"
GetType = "Long"
Case "HBRUSH":
GetType = "Long"
Case "HCOLORSPACE":
GetType = "Long"
Case "HCONV":
GetType = "Long"
Case "HCONVLIST":
GetType = "Long"
Case "HCURSOR":
GetType = "Long"
Case "HDC":
GetType = "Long"
Case "HDDEDATA":
GetType = "Long"
Case "HDESK":
GetType = "Long"
Case "HDROP":
GetType = "Long"
Case "HDWP":
GetType = "Long"
Case "HENHMETAFILE":
GetType = "Long"
Case "HFILE":
GetType = "Long"
Case "HFONT"
GetType = "Long"
Case "HGDIOBJ":
GetType = "Long"
Case "HGLOBAL":
GetType = "Long"
Case "HHOOK":
GetType = "Long"
Case "HICON":
GetType = "Long"
Case "HIMAGELIST":
GetType = "Long"
Case "HIMC":
GetType = "Long"
Case "HINSTANCE":
GetType = "Long"
Case "HKEY":
GetType = "Long"
Case "HKL":
GetType = "Long"
Case "HLOCAL":
GetType = "Long"
Case "HMENU":
GetType = "Long"
Case "HMETAFILE":
GetType = "Long"
Case "HMODULE":
GetType = "Long"
Case "HMONITOR":
GetType = "Long"
Case "HPALETTE":
GetType = "Long"
Case "HPEN":
GetType = "Long"
Case "HRESULT":
GetType = "Long"
Case "HRGN":
GetType = "Long"
Case "HRSRC":
GetType = "Long"
Case "HSZ":
GetType = "Long"
Case "HWINSTA":
GetType = "Long"
Case "HWND":
GetType = "Long"
Case "INT":
GetType = "Long"
Case "INT_PTR":
GetType = "Long"
Case "INT32":
GetType = "Long"
Case "INT64":
GetType = "Currency"
Case "IPADDR":
GetType = "Long"
Case "IPMASK":
GetType = "Long"
Case "LANGID":
GetType = "Long"
Case "LCID":
GetType = "Long"
Case "LONG":
GetType = "Long"
Case "LONG_PTR":
GetType = "Long"
Case "LONG32":
GetType = "Long"
Case "LONG64":
GetType = "Currency"
Case "LONGLONG":
GetType = "Currency"
Case "LPARAM":
GetType = "Any"
Case "LPBOOL":
GetType = "Long"
Case "LPBYTE":
GetType = "Long"
Case "LPCOLORREF":
GetType = "Long"
Case "LPCRITICAL":
GetType = "Long"
Case "LPCSTR":
GetType = "String"
IsByVal = True
Case "LPCTSTR":
GetType = "String"
IsByVal = True
Case "LPCVOID":
GetType = "Any"
IsByVal = True
Case "LPDWORD":
GetType = "Long"
Case "LPHANDLE"
GetType = "Long"
Case "LPINT":
GetType = "Long"
Case "LPLONG":
GetType = "Long"
Case "LPSTR":
GetType = "String"
Case "LPTSTR":
GetType = "String"
IsByVal = False
Case "LPVOID":
GetType = "Any"
IsByVal = False
Case "LPWORD":
GetType = "Long"
Case "LRESULT":
GetType = "Long"
Case "LUID":
GetType = "Long"
Case "PBOOL":
IsByVal = False
GetType = "Long"
Case "PBOOLEAN":
IsByVal = False
GetType = "Long"
Case "PBYTE":
IsByVal = False
GetType = "Long"
Case "PCHAR":
IsByVal = False
GetType = "Long"
Case "PCRITICAL_SECTION":
IsByVal = False
GetType = "Long"
Case "PCSTR":
GetType = "String"
IsByVal = True
Case "PCTSTR:"
GetType = "String"
IsByVal = True
Case "PDWORD":
IsByVal = False
GetType = "Long"
Case "PFLOAT":
IsByVal = False
GetType = "Long"
Case "PHANDLE":
IsByVal = False
GetType = "Long"
Case "PHKEY":
IsByVal = False
GetType = "Long"
Case "PINT":
IsByVal = False
GetType = "Long"
Case "PLCID":
IsByVal = False
GetType = "Long"
Case "PLONG":
IsByVal = False
GetType = "Long"
Case "PLUID":
IsByVal = False
GetType = "Long"
Case "POINTER_32":
IsByVal = False
GetType = "Long"
Case "POINTER_64":
IsByVal = False
GetType = "Currency"
Case "PSHORT":
IsByVal = False
GetType = "Long"
Case "PSTR":
IsByVal = False
GetType = "String"
Case "PTBYTE":
IsByVal = False
GetType = "Long"
Case "PTCHAR":
IsByVal = False
GetType = "Long"
Case "PUCHAR":
IsByVal = False
GetType = "Long"
Case "PUINT":
IsByVal = False
GetType = "Long"
Case "PULONG":
IsByVal = False
GetType = "Long"
Case "PUSHORT":
IsByVal = False
GetType = "Long"
Case "PVOID":
IsByVal = False
GetType = "Any"
Case "PWORD":
IsByVal = False
GetType = "Long"
Case "SERVICE_STATUS_HANDLE":
GetType = "Long"
Case "SHORT":
GetType = "Integer"
Case "SIZE_T":
GetType = "Long"
Case "SSIZE_T":
GetType = "Long"
Case "TBYTE":
GetType = "Byte"
Case "TCHAR":
GetType = "Byte"
Case "UCHAR":
GetType = "Byte"
Case "UINT":
GetType = "Long"
Case "UINT_PTR":
GetType = "Long"
Case "UINT32":
GetType = "Long"
Case "UINT64":
GetType = "Currency"
Case "ULONG":
GetType = "Long"
Case "ULONG_PTR":
GetType = "Long"
Case "ULONG32":
GetType = "Long"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -