I have been pulling out my hair lately trying to figure out why some functions I was using with a DLL seemed to mysteriously break. I had been rewriting an old DBC script for use with the dll. Making a longer story shorter, I thought it had to do with using DOUBLES in a C dll vs using FLOAT values. DOUBLES are twice as large (bitwise) as FLOATS and DBC can only handle FLOATS. So I recompiled the DLL with single precision - no luck!
I found my original DBC script to test this DLL and it worked - both with the old DLL and the newly compiled one? What the heck?
The difference, I found, was that I was using regular float variables in DBC in the original script (a# , value#, etc.) But in the new script, I was using float arrays (a#(2), value#(16), etc.)
From what I can tell, float arrays do not return an expected value from a DLL call that returns a float. Is this a known BUG?
Anyway maybe this post will save some headaches and also, (for myself at least) this solves problems with DLLs I thought couldn't be used with DBC because they simply didn't work. Maybe not so - could just be arrays with DLL calls are quirky.
I've uploaded a DLL that has a few functions that take double and float input and will return double or float output. I'm also including a test script I threw together to show how the array returns the incorrect value and how a regular float variable will return the correct one.
There's an extra function I stuck in this test DLL called MessageOut and it will output a simple message box (up to 255 characters long) if you want to use it for anything.
call dll,<num>,MessageOut,<title$>,<message$>
The DBC version I'm using is 1.13 with the patch from 2002.
[EDIT]
When running the included test script, I've seen only 1 case when the value 123.456 is returned as expected - when sent as a float and returned as a float using a DBC non-array float variable.
Enjoy your day.