大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> 用vb.net开发api viewer(5)

用vb.net开发api viewer(5)

时间: 2021-07-31 作者:daque

在名目中增添新项---类(parseapi.vb)代码如次imports system.ionamespace apipublic class parseapidim soldapi as stringdim snewapi as stringdim pfile as stringdim preader as streamreaderpublic sub new(byval sfile as string)if file.exists(sfile) thenpfile = sfileelsepfile = ""end ifend subpublic sub gettypeinfo()dim sreturn as stringdim scsharp as stringdim scsharpinput as stringdim skey as stringdim bstart as boolean = falsedim btypestatement as boolean = falseif pfile <> "" thenif not file.exists(pfile) thentypes = nothingreturnend ifdim sr as streamreader = file.opentext(pfile)dim input as stringinput = sr.readline()while not input is nothingif bstart = false and instr(1, input, apistarttype) <> 0 thenif not input.startswith("'") thenif split(input, " ").length() <= 2 thenskey = split(input, " ")(1).tostring()scsharpinput = inputinput = input.replace(apistarttype, apitype + apiscope + " structure ").tostring()scsharpinput = scsharpinput.replace(apistarttype, apitypecsharp + vbcrlf + apiscope + " " + apistructurecsharp).tostring() + apistartscopecsharpbstart = truebtypestatement = trueend ifend ifend ifif bstart thenif instr(1, input, apiendtype) <> 0 thenscsharpinput = inputinput = input.replace(apiendtype, "end structure").tostring()scsharpinput = scsharpinput.replace(apiendtype, apiendscopecsharp).tostring()sreturn += input & vbcrlfsreturn = sreturn.replace(apilong, apiinteger)scsharp += scsharpinput & vbcrlfscsharp = scsharp.replace(apilong, apiinteger)scsharp = changedeclartion(scsharp)types.add(skey, sreturn)types.add(skey, scsharp, true)skey = ""sreturn = ""scsharp = ""bstart = falseelsedim breturn as boolean = falsedim smarshal as string = ""dim scsharpmarshal as string = ""dim stmp as stringbreturn = marshalstringvalue(input, smarshal)if breturn thenscsharpmarshal = smarshal.replace("<", "[")scsharpmarshal = scsharpmarshal.replace(">", "]" + vbcrlf)stmp = scsharpmarshal.substring(scsharpmarshal.indexof("]" + vbcrlf) + 1)stmp = stmp.replace(apiscope, "").trim()stmp = changenotation(stmp)scsharp += scsharpmarshal.substring(0, scsharpmarshal.indexof("]" + vbcrlf) + len("]" + vbcrlf)) + apiscope + stmp + apiendstatementcsharpsreturn += smarshal + vbcrlfelsebreturn = falsesmarshal = ""breturn = marshalarrayvalue(input, smarshal)if breturn and (not btypestatement) thenscsharpmarshal = smarshal.replace("<", "[")scsharpmarshal = scsharpmarshal.replace(">", "]" + vbcrlf)stmp = scsharpmarshal.substring(scsharpmarshal.indexof("]" + vbcrlf) + 1)stmp = stmp.replace(apiscope, "").trim()stmp = changenotation(stmp)scsharp += scsharpmarshal.substring(0, scsharpmarshal.indexof("]" + vbcrlf) + len("]" + vbcrlf)) + apiscope + stmp + apiendstatementcsharpsreturn += smarshal + vbcrlfelseif btypestatement thenscsharp += scsharpinputsreturn += input & vbcrlfelsestmp = changenotation(scsharpinput)scsharp += apiscope + stmp & apiendstatementcsharpsreturn += apiscope + input & vbcrlfend ifend ifend ifbtypestatement = falseend if'threading.thread.sleep(1)input = sr.readline()scsharpinput = inputend whilesr.close()returnelsereturnend ifend subpublic sub getconstinfo()dim sreturn as stringdim skey as stringdim scsharp as stringif pfile <> "" thenif not file.exists(pfile) thentypes = nothingreturnend ifdim sr as streamreader = file.opentext(pfile)dim input as stringinput = sr.readline()while not input is nothingif instr(1, input, apistartconst) <> 0 then'check for the commentif not input.startswith("'") then'look ahead for false dataif split(input, "=").length() <= 2 thenskey = split(input, " ")(1).tostring()input = apiscope & inputscsharp = inputscsharp = scsharp.replace("const", "const int") + ";"scsharp = scsharp.replace("'", "//")constants.add(skey, input)constants.add(skey, scsharp, true)end ifend ifend if'threading.thread.sleep(1)input = sr.readline()end whilesr.close()returnelsereturnend ifend subpublic sub getdeclareinfo()dim sreturn as stringdim sstructures as stringdim skey as stringdim scsharp as stringdim scsharpstruct as stringdim scsharpreturntype as stringdim slib as stringif pfile <> "" thenif not file.exists(pfile) thentypes = nothingreturnend ifdim sr as streamreader = file.opentext(pfile)dim input as stringinput = sr.readline()while not input is nothingif instr(1, input, apistartdeclare) <> 0 then'check for the commentif not input.startswith("'") then'look ahead for false dataif split(input, " ").length() > 5 thenskey = split(input, " ")(2).tostring()slib = split(input, " ")(4).tostring()if instr(slib, ".") = 0 then slib = slib.substring(0, len(slib) - 1) + ".dll" + slib.substring(len(slib) - 1)sstructures = ""trysstructures = input.substring(input.indexof("(") + 1, ((input.indexof(")")) - (input.indexof("(") + 1)))scsharpstruct = sstructuresif split(input, " ")(1).trim().tostring() = "function" thenscsharpreturntype = split(input.substring(input.indexof(")") + 1), "as ")(1).tostring()end ifcatch e as exceptionsstructures = ""end trydim vdata() as string = sstructures.split(",")dim vcsharpdata() as string = sstructures.split(",")dim icount as integer = vdata.length()dim i as integerdim breturn as booleandim smarshalvalue as stringdim scsharpmashal as stringdim vvariable() as stringif icount >= 0 thenfor i = 0 to icount - 1breturn = falsevvariable = vdata(i).trim().split(" ")dim stmp as stringstmp = vcsharpdata(i)stmp = changenotation(stmp)if vvariable.length() >= 2 thenif vvariable.length() > 3 thenbreturn = marshalstructvalue(vvariable(3).tostring(), smarshalvalue)elsebreturn = marshalstructvalue(vvariable(2).tostring(), smarshalvalue)end ifend ifif breturn thenvdata(i) = smarshalvalue + " " + vdata(i)vcsharpdata(i) = apistructcsharp + " " + stmpelsevcsharpdata(i) = stmpend ifnextsstructures = string.join(",", vdata)if sstructures <> "" theninput = input.replace(input.substring(input.indexof("(") + 1, ((input.indexof(")")) - (input.indexof("(") + 1))), sstructures)end ifend ifscsharp = apidllimportecsharpscsharp = replace(scsharp, apidllimport, slib) + vbcrlfscsharp += apiscope + " " + apistartcsharp + iif(scsharpreturntype <> "", " " & scsharpreturntype, " void ") + " " & skey + "(" + iif(vcsharpdata is nothing, " ", join(vcsharpdata, ",")) + ")" + apiendstatementcsharpscsharpreturntype = ""scsharp = changedeclartion(scsharp)input = apiscope & inputinput = input.replace(apilong, apiinteger)declares.add(skey, input)declares.add(skey, scsharp, true)end ifend ifend if'threading.thread.sleep(1)input = sr.readline()end whilesr.close()returnelsereturnend ifend subprivate function marshalstructvalue(byval stra as string, byref sreturn as string) as booleanif string.compare(stra, "long") = 0 then return falseif string.compare(stra, "integer") = 0 then return falseif string.compare(stra, "byte") = 0 then return falseif string.compare(stra, "any") = 0 then return falseif string.compare(stra, "boolean") = 0 then return falseif string.compare(stra, "string") = 0 then return falsesreturn = apistructreturn trueend functionprivate function marshalarrayvalue(byval stra as string, byref sreturn as string) as booleandim vdata as stringdim vvariable as stringdim i as integer'check for the array in the structureif stra.indexof("(") > 0 then'got the array, marshal this arrayvdata = stra.substring(stra.indexof("(") + 1, ((stra.indexof(")")) - (stra.indexof("(") + 1)))vvariable = apiarrayvvariable = replace(vvariable, apisizeofarray, vdata)stra = stra.replace(vdata, "")stra = stra.replace("(", "")stra = stra.replace(")", "")sreturn = vvariable & apiscope & strareturn trueend ifreturn falseend functionprivate function marshalstringvalue(byval stra as string, byref sreturn as string) as booleandim vdata as stringdim vvariable as stringdim i as integer'check for the array in the structureif stra.indexof("*") > 0 then'got the array, marshal this arrayvdata = stra.substring(stra.indexof("*") + 1)vvariable = apistringvvariable = replace(vvariable, apisizeofarray, vdata)stra = stra.replace(vdata, "")stra = stra.replace("*", "")stra = stra.trim()sreturn = vvariable & apiscope & strareturn trueend ifreturn falseend functionprivate function changedeclartion(byval stra as string) as stringstra = stra.replace(apiinteger, apiintegercsharp)stra = stra.replace(apilong, apiintegercsharp)stra = stra.replace(apibytevb, apibytecsharp)stra = stra.replace(apifloatvb, apifloatcsharp)stra = stra.replace(apistrvb, apistrcsharp)stra = stra.replace(apianyvb, apiintegercsharp)return straend functionprivate function changenotation(byval stra as string) as stringdim strold as stringstra = stra.replace(apibyrefvb, "")stra = stra.replace(apibyvalvb, "")if instr(stra, "'") > 0 thenstra = stra.substring(0, instr(stra, "'") - 1).trim()end ifdim vdata() as string = split(stra.trim().tostring(), apiseperatoras)if vdata.length > 1 thenstrold = vdata(vdata.length - 1) + " " + vdata(vdata.length - 2)return stroldend ifreturn ""end functionend classend namespace

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.