Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VB Call to API vs VFP
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00255827
Message ID:
00256194
Views:
27
>If I Replace the BYTE with STRING in VFP, if get the famous Fatal exception error C00005 !, When i use INTEGER, it works but returns wrong values.
>
>Yes the variable names have to be the same as the one in the DLL, it was just a typo.
>

actually, the variable names can be anything you want them to be; the name of the entrypoint must be the same, and is case-sensitive. IOW, SomeFunctionName is not the same as SOMEFUNCTIONNAME in the first part of the DECLARE, but after, that, variable names are ignored (they're just treated as comments in the DECLARE, and can be omitted entirely.)

When you invoke the function, you can use any name you like for the parameters (the variables must exist, be in scope, and must have a proper data type to match the parameter declaration), and in fact you can pass an appropriate literal or constant when you don't need to see what the DLL does to whatever you pass it. The order of the variables and their data types must match in both the DECLARE...DLL and the invocation of the function, with the single exception (that I know of) being that if your DECLARE...DLL has a STRING @ parameter, passing an integer 0 works as a null pointer (equivalent to VB's vbNull construct.)

>A Variable Type BYTE in VB is i Think an Integer value from 0 to 255, so why is INTEGER dont work in VFP.
>

To VFP, an INTEGER in a DECLARE...DLL is a 4 byte construct, as opposed to a SHORT, which is two bytes, and can only be declared as the return type. Christof Lange pointed out a problem with declared SINGLE and DOUBLE parameters; while the value is translated properly (the data value is moved for the right number of bytes) the number of decimal places for the numeric variable is not adjusted if a SINGLE or DOUBLE is passed by reference and the value is changed by the DLL. A simple workaround is to make sure that the necessary precision is defined for the variable ahead of time, by doing something like:

nPassedAsDouble = 1.23 && variable is now only 2 decimal places
nPassedAsDouble = nPassedAsDouble + 0.0000000000 && 10 decimal places now

DOUBLE can be up to 18 decimal places in precision.


>Tanks
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform