Looking for header translation tutorial / guide; finally making jump to PB

Windows specific forum
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

Looking for header translation tutorial / guide; finally making jump to PB

Post by Thumper »

Greetings,

I've been around here for a while and tinkered with PureBasic here and there (small stuff) but claim no real proficiency with it as I'm still stuck in the PowerBasic + handwritten EZGUI. The old stuff still runs great but I need to start a new project and want to make the transition here at this time.

I have searched the forums for posts that might / hopefully present a tutorial / guide on translating c headers to be usable in PureBasic but have not run across one. Does anyone know off-hand any post(s) that contain such a tutorial ?

For reference, the header conversion hurdles I need to get over are (at this point):
  • direct access to FTDI chips (need more than COM port can provide)
  • Debenu Quick PDF Library generator
Plus
  • create a window / gadget showing live video from an HDMI-to-USB capture device (OpenCV looked promising but the interface library is no longer available and will keep looking for other options)
  • MP3 and video player (I expect the built-in functions will suffice)
  • Text and window animation functions - text / image zoom in / out, windows slide in / out, etc (but I honestly haven't started looking at this but I might learn the 3D functions for the fun of it)
  • Low-level low-speed USB communications (likely HID-class...TBD)
I'm sure I'll hit other hurdles but if anyone can point me to a header conversion tutorial / guide, that would be a big help and get the started.

Cheers!
Dan

(This is my fourth time to type this... it keeps timing out and erasing what I entered, so please forgive errors and lack of coherency. It sounded better the first time!)
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
User avatar
idle
Always Here
Always Here
Posts: 5888
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Looking for header translation tutorial / guide; finally making jump to PB

Post by idle »

porting c headers is easy enough for the most part it's just a case of remembering

short = ,u or .w (unicode or word unicode being unsigned)
int = .l (long)
long = .i (integer)
long long = .q (quad)
char = .a or .b
*char = *ptr (pointer)

For functions that take ascii or utf8 you have the pseudo-types p-ascii p-utf8
so your input string is converted to the respective type.

if you need to deal with Endiness you can find byteswap functions on the forum

You may also need to pay attention to the alignment of imported structures, you can use #PB_Structure_AlignC

Code: Select all

Structure foo Align #PB_Structure_AlignC 
  a.a
  u.u
  l.l
EndStructure 

Structure bar  
  a.a
  u.u
  l.l
EndStructure 

Debug SizeOf(foo)
Debug SizeOf(bar) 



if you need a HID lib ask I have hidapi and libusb
No idea about FTDI driver access

Also note your better off sticking to importing from DLL's and x64 if the objective is to eventually link to static libs
you can use ImportC "my.lib" and then switch to the static build when your done but linking to static libs can be a real pain as it's dependent on the CRT version used.

If you only need to use Dlls probably better to go with openlibrary and prototypes.

There are PDF tools about might need to google site search to find them

All the native PB gui functions are just old win32.

Hope that helps a little.
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

Re: Looking for header translation tutorial / guide; finally making jump to PB

Post by Thumper »

#PB_Structure_AlignC noted. Also, FTDI and Debenu include both 32 and 64-bit DLLs, so I'll be okay there. I've used QuickPDF for years and hope to keep using it.

Is there a "best practice" on formatting or handling the conversions?

Below is what I'm playing with along with some verbose notes so that you can tell what is going on in my mind. Well, nevermind. I know I'm probably not handling the pointer correctly. Otherwise, am I on the right track for this simple function and making the right assumptions:
' FTD2XX_API
' ULONG WINAPI FT_Open(
' int deviceNumber,
' PVOID *pHandle
' );
' (define a prototype for each calling parameters)
' (a prototype can be used multiple times if more than function has the exact same parameters)

Code: Select all

prototype.i P_FT_Open ( deviceNumber.i, *pHandle )
' (I made this P_ on purpose for clarity in the global below)
' (this could be called "P_FT_dev_handle" for all functions that get passed device number and handle )

Code: Select all

global libraryFTDI.i = openLibrary ( #PB_Any, "FTDI2XX.DLL" )
' (using #PB_Any so that I don't have any library conflicts)
' (made global so that I can close the DLL if needed and at the end of the program)

Code: Select all

if libraryFTDI then

     global C_FT_Open.P_FT_Open = getFunction ( libraryFTDI, "FT_Open" )
' (I did the C_ here to emphasize this is what I will call to open the FTDI library.)
' (does case matter for the function name?)

Code: Select all

endIf

FTDIdeviceNumber.i = 0 
' (just assume that is right for this example)

Code: Select all

hFTDI.i = 0
' (creating the variable to store the handle)

Code: Select all

result.i = C_FT_Open ( FTDIdeviceNumber, hFTDI )
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
User avatar
idle
Always Here
Always Here
Posts: 5888
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Looking for header translation tutorial / guide; finally making jump to PB

Post by idle »

That looks OK but the int is .l (long) in pb
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

Re: Looking for header translation tutorial / guide; finally making jump to PB

Post by Thumper »

Okay, lexadis kicked in.

long > int
int > long

That will kick me along with the old habit of "if ... then" and "end if", which I just caught in that last posting.

Now if I need to pass or receive a string, anything special there besides being sure to pre-allocate enough bytes ?
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
User avatar
idle
Always Here
Always Here
Posts: 5888
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Looking for header translation tutorial / guide; finally making jump to PB

Post by idle »

Thumper wrote: Sun Sep 29, 2024 4:03 am Okay, lexadis kicked in.

long > int
int > long

That will kick me along with the old habit of "if ... then" and "end if", which I just caught in that last posting.

Now if I need to pass or receive a string, anything special there besides being sure to pre-allocate enough bytes ?
if strings are returned use peekS

Code: Select all

UseZipPacker()

ImportC ""     ;since we link to zlib with usezip packer we can use "" to import 
  zlibVersion()
EndImport   

Debug PeekS(zlibVersion(),-1,#PB_UTF8) 
Post Reply