Translating C/C++ headers to FreeBASIC

Started by Paul Squires, April 23, 2015, 04:46:54 PM

Previous topic - Next topic

Paul Squires

The following link contains helpful information if you are trying to convert existing C/C++ .h header files to FreeBASIC .bi files.

http://www.freebasic.net/wiki/DevBindingCreation
Paul Squires
PlanetSquires Software

David Warner

Here's another link which might be useful.

Comparison table of C/C++ and FreeBASIC
http://www.freebasic.net/wiki/wikka.php?wakka=TblComparisonC

José Roca

They don't seem to understand that passing a parameter by reference is the same that passing a pointer to that parameter by value.

For example, they use:


declare function GetMessageW(byval lpMsg as LPMSG, byval hWnd as HWND, byval wMsgFilterMin as UINT, byval wMsgFilterMax as UINT) as WINBOOL
declare function TranslateMessage(byval lpMsg as const MSG ptr) as WINBOOL
declare function DispatchMessageW(byval lpMsg as const MSG ptr) as LRESULT

dim wMsg as MSG
while( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )
   TranslateMessage( @wMsg )
   DispatchMessage( @wMsg )
wend


instead of:


DECLARE FUNCTION GetMessageW (BYREF lpMsg AS MSG, BYVAL hWnd AS HANDLE, BYVAL wMsgFilterMin AS DWORD, BYVAL wMsgFilterMax AS DWORD) AS LONG
DECLARE FUNCTION TranslateMessage (BYREF lpMsg AS MSG) AS LONG
DECLARE FUNCTION DispatchMessageW (BYREF lpMsg AS MSG) AS LRESULT

DIM wMsg AS MSG
WHILE (GetMessage(wMsg, NULL, 0, 0) <> FALSE)
   TranslateMessage(wMsg)
   DispatchMessage(wMsg)
WEND


Both do exactly the same, but with the BASIC-friendly version you don't have to use @.

Marc Pons

Hi Jose
obviously they know " passing a parameter by reference is the same that passing a pointer to that parameter by value" , probably it is just because they where more  "c code" thinking at the beginning...

If you have a look on the previous versions , at the beginning  "fb lang" ,  parameters were  by default byref ,  now default its byVal , except for strings and udt wich are by default byref (if i remember correctly)

it is also a byref return possibility for functions ...

José Roca

If they understand it, why they don't practice it? It is like if I had translated the headers for PowerBASIC using BYVAL somegthing PTR instead of BYREF, forcing you to use VARPTR.

James Fuller

I'm a bit confused on 64bit?
If 64bit needs -gen gcc why go to all the trouble of translating the headers -> Fb ??

James