Com TypeLibBrowser
Posted: Thu Oct 13, 2022 10:19 pm
I've been working with the BlackMagic Decklink cards for quite a few years. I've written software in C# and Powerbasic to access the features. Recently I've been working with Purebasic as Powerbasic seems to be in decline. Purebasic is a fine product and I'm enjoying using it. Sadly it doesn't have native COM support for windows so working the Decklink api has been an "adventure". One of the things that helped me get through it has been having a TypeLib Browser. As far as I know there isn't one that produces Purebasic code, so I used one by Jose Roca (http://www.jose.it-berater.org/) that produces Powerbasic code, which can then be converted. If you'd like to down load it, use the above link to make an account and then use this link http://www.jose.it-berater.org/smfforum ... oard=395.0 to get to the right page. The link on the home page is for an older version and doesn't go anywhere useful.
I wrote the following to convert the Powerbasic syntax to Purebasic. It's a little rough and I hard coded my input and output files. And you probably will have to do some minor tweaks to the .pbi file but it's a start:
I hope it's helpful.
I wrote the following to convert the Powerbasic syntax to Purebasic. It's a little rough and I hard coded my input and output files. And you probably will have to do some minor tweaks to the .pbi file but it's a start:
Code: Select all
EnableExplicit
NewList MyList.S()
Define i.l,j.l,x.l,bEnum.l
Define a$,b$,c$
Global flnum.l = ReadFile(#PB_Any,"C:\PureBasic Projects\DeckLink Test\DeckLinkApi.inc")
If flnum
While Eof(flnum) = 0 ; loop as long the 'end of file' isn't reached
AddElement(myList())
a$ = ReadString(flnum)
If Right(a$,4) = "As _"
a$ = ReplaceString(a$,"As _","As ")
b$ = ReadString(flnum)
a$ = a$ + Trim(b$)
EndIf
If Right(a$,2) = " _"
a$ = ReplaceString(a$," _"," ")
b$ = ReadString(flnum)
a$ = a$ + Trim(b$)
EndIf
myList() = a$
b$ = ""
Wend
CloseFile(flnum)
EndIf
Dim Coms.s(ListSize(MyList())-1)
x = 0
For i = 0 To ListSize(MyList())-1
SelectElement(mylist(), i)
a$ = myList()
If FindString(a$,"End Enum")
a$ = ReplaceString(a$,"End Enum","EndEnumeration")
bEnum = #False
EndIf
If bEnum
a$ = Space(4)+ "#" + Trim(a$)
EndIf
a$ = ReplaceString(a$,"'",";")
a$ = ReplaceString(a$,"&H","$")
a$ = ReplaceString(a$,"ByVal ","")
a$ = ReplaceString(a$,"ByRef ","*")
a$ = ReplaceString(a$,"Method ","")
a$ = ReplaceString(a$,"Singular","")
If Left(a$,5) = "Type "
a$ = ReplaceString(a$,"Type ","Structure ")
EndIf
a$ = ReplaceString(a$,"End Type","EndStructure ")
If FindString(a$,"Enum ")
a$ = ReplaceString(a$,"Enum ","Enumeration ")
bEnum = #True
EndIf
a$ = ReplaceString(a$,"End Interface","EndInterface")
If FindString(a$,"Guid$(")
a$ = ReplaceString(a$,"Guid$(","")
a$ = Mid(a$,0,Len(a$)-1)
EndIf
a$ = ReplaceString(a$,"$CLSID_","#CLSID_")
a$ = ReplaceString(a$,"$IID_","#IID_")
If FindString(a$,") As Long")
a$ = ReplaceString(a$,") As Long",")")
j = FindString(a$,"(")
If j:a$ = InsertString(a$,".l",j):EndIf
EndIf
If FindString(a$,") As Dword")
a$ = ReplaceString(a$,") As Dword",")")
j = FindString(a$,"(")
If j:a$ = InsertString(a$,".l",j):EndIf
EndIf
a$ = ReplaceString(a$," As Long",".l")
a$ = ReplaceString(a$," As WString",".s")
a$ = ReplaceString(a$," As Quad",".q")
a$ = ReplaceString(a$," As Byte",".b")
a$ = ReplaceString(a$," As Double",".d")
a$ = ReplaceString(a$," As Dword",".l")
a$ = ReplaceString(a$," As ",".")
j = FindString(a$,"Inherit IUnknown")
If j
a$ = Coms(x-1)
j = FindString(a$,"#IID_")
b$ = Left(a$,j-1)
c$ = Mid(a$,j)
a$ = b$ + "Extends IUnknown ;" + c$
Coms(x-1) = a$
AddGadgetItem(lv1,-1,a$)
Continue
EndIf
Coms(x) = a$
x = x + 1
AddGadgetItem(lv1,-1,a$)
Next
flnum = OpenFile(#PB_Any,"C:\PureBasic Projects\DeckLink Test\DeckLinkApi.pbi")
For i = 1 To x
WriteStringN(flnum,coms(i),#PB_Ascii)
Next
CloseFile(flnum)