PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Paul Squires on April 23, 2015, 04:46:54 PM

Title: Translating C/C++ headers to FreeBASIC
Post by: Paul Squires on April 23, 2015, 04:46:54 PM
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
Title: Re: Translating C/C++ headers to FreeBASIC
Post by: David Warner on April 26, 2015, 06:52:36 AM
Here's another link which might be useful.

Comparison table of C/C++ and FreeBASIC
http://www.freebasic.net/wiki/wikka.php?wakka=TblComparisonC (http://www.freebasic.net/wiki/wikka.php?wakka=TblComparisonC)
Title: Re: Translating C/C++ headers to FreeBASIC
Post by: José Roca on April 26, 2015, 06:27:53 PM
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 @.
Title: Re: Translating C/C++ headers to FreeBASIC
Post by: Marc Pons on April 27, 2015, 07:58:09 AM
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 ...
Title: Re: Translating C/C++ headers to FreeBASIC
Post by: José Roca on April 27, 2015, 08:47:41 AM
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.
Title: Re: Translating C/C++ headers to FreeBASIC
Post by: James Fuller on April 27, 2015, 10:24:15 AM
I'm a bit confused on 64bit?
If 64bit needs -gen gcc why go to all the trouble of translating the headers -> Fb ??

James