WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DllCall Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

DLLCALL: Float as a passed param to DLLCALL

Keywords:     floating point numbers and DLLCall

Question:

Is there an example of how to pass a float to a DLL?

I have many Dlls that I would like to pass a single (or a couple) floats to and have been unsuccessful, in an example as simple as:

=======DLL==========
float WINAPI MyFloatFunc(float PassedFloat)
{
PassedFloat = 10.0 + PassedFloat;
return PassedFloat;
}

=======WBT==========
myfloat=1.123
a1=DllCall("mydll.dll", long:"MyFloatFunc",long:myfloat)
Message("Returned a Value","MyFloatFunc returned %a1%")
a1 gets printed as: "1240488"

When I print out the value PassedFloat from inside the DLL,(after sprintf %f into a string and printing with MessageBox) it prints a "0.00000".

What did I miss? What is the proper parameter type for a simple FLOAT?

Answer:

EEEK

No direct support for Float. However it is possible to do by changing your routines. Something like this TOTALLY UNDEBUGGED CODE.

void WINAPI MyFloatFunc(DOUBLE * PassedFloat, DOUBLE * AsnwerFloat)
{
*AnswerFloat = 10.0 + *PassedFloat;
return;
}

Then in WinBatch
;add 10.0 to zorkfloat
zorkfloat=123.45

pass=BinaryAlloc(8)
ans=BinaryAlloc(8)
BinaryEODSet(ans,8)
BinaryPokeFlt(pass,0,zorkfloat)

DllCall("your.dll",void:"MyFloatFunc",lpbinary:pass,lpbinary:ans)

zorkplus10=BinaryPeekFlt(ans,0)

Message(zorkfloat,zorkplus10)

;----------

Article ID:   W12869
Filename:   Float as a passed param to DLLCALL.txt
File Created: 1999:04:15:16:50:12
Last Updated: 1999:04:15:16:50:12