Page 1 of 1

Modify the CallFunction Procedure

Posted: Sat Jul 05, 2003 4:36 pm
by blueb
Is it possible to add or change the command CallFunction?

Calling procedures from other DLL's requires an extra effort if the returned value is NOT a long. In fact if you get it wrong the PureBasic compiler GPF's.

----------------------------------
The examples are from Edwin Knoppert's great 'General Purpose Library'
(tons of functions) (www.hellobasic.com)

GLP Help file: Declare Function ShowFolder Lib "pbsgplib.dll" Alias "ShowFolder"( ByVal szPath As String ) As Long

As you can see his procedure returns a long value... so nothing special needs doing
CallFunction( 0, "ShowFolder", "c:\Windows")

but if a DLL procedure returns a string value, such as:

GLP Help file: Declare Function GetDiskLabel Lib "pbsgplib.dll" Alias "GetDiskLabel"( ByVal szDrive As String ) As String
we have to put the return value in a memory buffer ...
*Ans = CallFunction( 0, "GetDiskLabel", "c:\")
ans$ = PeekS(*Ans)
MessageRequester("", ans$, 0)

Since 3rd party DLL's are an important part of PureBasic (e.g. Windows DLL's) perhaps CallFunction() could be modified to 'incorporate' the peek() functions for the programmer.

for example:

returnValue = CallFunction( 0, etc.etc....) ......... a long is assumed so existing code will not break
returnValue.b = CallFunctionB( 0, etc.etc....) ... a byte value is returned
returnValue.f = CallFunctionF( 0, etc.etc....) ... a float value is returned
returnValue.l = CallFunctionL( 0, etc.etc....) ... same as first line, used to maintain consistancy
returnValue.s = CallFunctionS( 0, etc.etc....) ... a string is returned
returnValue.w = CallFunctionW( 0, etc.etc....) ... a word value is returned

Just a thought. Perhaps there's an easier way. :idea:

One option could be: CallFunction( 0, function call, [parameters], [Return Type]) but this might get confusing.

Blueb