Float variables to external functions (dll)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by VeKem.
Hello,
I tried to use PureBasic float variables as parameters for an external dl-function (inside a dll written in PowerBASIC). The float types seems to have a specialo/non standard format (?). Insode PowerBASIC there is a single type (also 32bit float), but the results are trash.
Knows anybody handling the PureBasic floats outside in a correct way?
Thanks!
Hello,
I tried to use PureBasic float variables as parameters for an external dl-function (inside a dll written in PowerBASIC). The float types seems to have a specialo/non standard format (?). Insode PowerBASIC there is a single type (also 32bit float), but the results are trash.
Knows anybody handling the PureBasic floats outside in a correct way?
Thanks!
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Fred - AlphaSND
PureBasic use the regular, native x86 32 bit float representation. This format is perfectly compatiable with all C/C++ compiler on Windows, so I guess you better have to tell to the PowerBasic team how they have coded that .The float types seems to have a specialo/non standard format (?).
Fred - AlphaSND
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Rings.
x.f = 12.589
use
CallFunctionFast(lpProc.l, PeekL(@x) )
instead of
CallFunctionFast(lpProc.l, x.f)
This works, but i think there is a problem with floats(single).
Only Longs are dropped on the stack.
Its a long way to the top if you wanna .....CodeGuru
x.f = 12.589
use
CallFunctionFast(lpProc.l, PeekL(@x) )
instead of
CallFunctionFast(lpProc.l, x.f)
This works, but i think there is a problem with floats(single).
Only Longs are dropped on the stack.
Its a long way to the top if you wanna .....CodeGuru
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Hum, may be I've spoken a little bit faster . I will take a look.
Ok, here is the explaination:
It can't be fixed for now, CallFunction() is a purelibrary and I've fixed the parameter to #Long so the floats are automatically transformed to long.
Yhe PeekL() solution is the way to go for now. I will add an #Any paramater to allow every types in the next version..
Thanks for this report !
Edited by - fred on 09 April 2002 18:21:32
Hum, may be I've spoken a little bit faster . I will take a look.
Ok, here is the explaination:
It can't be fixed for now, CallFunction() is a purelibrary and I've fixed the parameter to #Long so the floats are automatically transformed to long.
Yhe PeekL() solution is the way to go for now. I will add an #Any paramater to allow every types in the next version..
Thanks for this report !
Edited by - fred on 09 April 2002 18:21:32
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
BTW, Fred, I can't find any doc about how to code library functions with variable arguments number, and how to know how many arguments have been passed. Is that number passed in edx or how? What to put in the .Desc file?
Thanks in advance (BTW, Internet has returned home
Bye,
El_Choni
BTW, Fred, I can't find any doc about how to code library functions with variable arguments number, and how to know how many arguments have been passed. Is that number passed in edx or how? What to put in the .Desc file?
Thanks in advance (BTW, Internet has returned home

Bye,
El_Choni
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by VeKem.
Thanks to Rings!
Fred,
thanks for your info, PowerBasic also uses internally the standard float (single) type. PeekL(...) told us the solution. Fine, you plan this #Any-parameter!
Addition: could you make a Declare-Statement for DDL-Calls, something like
Declare DllFunc.l(ParCount) lib DLLName$
...
;Pure-Code:
result = DllFunc(...)
so we can use it in PureBasic very easy? (No OpenLibrary, IsFunction, CallFunction...)
Thanks to Rings!
Fred,
thanks for your info, PowerBasic also uses internally the standard float (single) type. PeekL(...) told us the solution. Fine, you plan this #Any-parameter!
Addition: could you make a Declare-Statement for DDL-Calls, something like
Declare DllFunc.l(ParCount) lib DLLName$
...
;Pure-Code:
result = DllFunc(...)
so we can use it in PureBasic very easy? (No OpenLibrary, IsFunction, CallFunction...)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
I hope the names don't change...
I find OpenLibrary and CallFunction very easy to use and the names make sense to me. (and they follow the naming convention of other PB commands... OpenWindow, OpenConsole, OpenFile, OpenDatabase, etc.)
Just my 2 cents
I hope the names don't change...
I find OpenLibrary and CallFunction very easy to use and the names make sense to me. (and they follow the naming convention of other PB commands... OpenWindow, OpenConsole, OpenFile, OpenDatabase, etc.)
Just my 2 cents

-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by VeKem.
Paul,
I think, the naming convention of PB commands is good but if you only needs one command accessing a ddl function makes easier coding and
Fred,
thanks you thinking about
CallLibraryFunction(LibName$, FunctionName$, Args...) !
>But it will have a performance impact
Not much, because calling (internally) OpenLibrary etc. will force Windows only to increment a counter on the dll loading. In other languages I used to load the librarie ones (or before a whole block accessing it) and close it at the program end (or after the calling block). So an OpenLibrary is okay, but why identify a library with own #Library-Numbers, its handle is enough to do this.
What happens I open two different libs using the same Number?
OpenLinrary(0, "own01.dll")
OpenLinrary(0, "own02.dll")
Thanks for your great job on PureBasic!
Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User
Paul,
I think, the naming convention of PB commands is good but if you only needs one command accessing a ddl function makes easier coding and
Fred,
thanks you thinking about
CallLibraryFunction(LibName$, FunctionName$, Args...) !
>But it will have a performance impact
Not much, because calling (internally) OpenLibrary etc. will force Windows only to increment a counter on the dll loading. In other languages I used to load the librarie ones (or before a whole block accessing it) and close it at the program end (or after the calling block). So an OpenLibrary is okay, but why identify a library with own #Library-Numbers, its handle is enough to do this.
What happens I open two different libs using the same Number?
OpenLinrary(0, "own01.dll")
OpenLinrary(0, "own02.dll")
Thanks for your great job on PureBasic!
Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
And will a program be faster only if I use CallLibraryFunction
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
So PureBasic will be fasterI will probably add an extra function which will do all this:
CallLibraryFunction(LibName$, FunctionName$, Args...). But it will have a performance impact..
Fred - AlphaSND
And will a program be faster only if I use CallLibraryFunction
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Fred - AlphaSND
The first library is automatically closed/freed. That's the magic of using number instead handle. You never have to take care of previously objects for the same number. This is valid for any library.. For example, LoadImage(0,"2.bmp") followed by LoadImage(0,"1.bmp") with free the first one. In other langage, you will have to call FreeImage(0) before.. And of course, PureBasic can keep track easely (and very quickly) of all objects and free them when the program end/crashs.What happens I open two different libs using the same Number?
OpenLinrary(0, "own01.dll")
OpenLinrary(0, "own02.dll")
Fred - AlphaSND
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by VeKem.
Fred,
I understand this behavoiur of PureBasic, but what's about this
(something like pseudo code):
;***********************************
; ...
Declare ExternalProc(value.l)
If OpenLibrary(0, "user32.dll")
...
Result.l = CallFunction(0, "FuncName", ...)
ExternalProcedure(Result.l)
Result.l = CallFunction(0, "AnotherFuncName", ...) ; but there is no "0"-Library
CloseLibrary(0) ;...
EndIf
;...
Procedure ExternalProc(value.l)
; this could be a procedure from another coder or inside an include file,
; something I didn't write myself and (!) I do not want to check every
; time using it
If OpenLibrary(0, "mydll.dll") ; => closes the *actuall* with "0" opened dll!
;... doing something
CloseLibrary(0) ; now no "0"-Library opend any more
EndIf
EndProcedure
;***********************************
There is no way to check which number actually is used to avoid an automtic closing. What's you opinion on this? Thanks!
Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User
Fred,
I understand this behavoiur of PureBasic, but what's about this
(something like pseudo code):
;***********************************
; ...
Declare ExternalProc(value.l)
If OpenLibrary(0, "user32.dll")
...
Result.l = CallFunction(0, "FuncName", ...)
ExternalProcedure(Result.l)
Result.l = CallFunction(0, "AnotherFuncName", ...) ; but there is no "0"-Library
CloseLibrary(0) ;...
EndIf
;...
Procedure ExternalProc(value.l)
; this could be a procedure from another coder or inside an include file,
; something I didn't write myself and (!) I do not want to check every
; time using it
If OpenLibrary(0, "mydll.dll") ; => closes the *actuall* with "0" opened dll!
;... doing something
CloseLibrary(0) ; now no "0"-Library opend any more
EndIf
EndProcedure
;***********************************
There is no way to check which number actually is used to avoid an automtic closing. What's you opinion on this? Thanks!
Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User