-----------------------------------------------
DECLARE AND WIN32API
January 2026
-----------------------------------------------
CCB
1. THE DECLARE STATEMENT SYNTAX (from dv_foxhelp9.chm):
DECLARE [cFunctionType] FunctionName IN LibraryName [AS AliasName]
[cParamType1 [@] ParamName1, cParamType2 [@] ParamName2, ...]
IN LibraryName
Specifies the name of the external shared library containing the function specified with FunctionName.
If you specify WIN32API for the LibraryName,
Visual FoxPro searches for the 32-bit Windows .dll function in:
1, Kernel32.dll,
2, Gdi32.dll,
3, User32.dll,
4, Mpr.dll,
5, and Advapi32.dll.
2. REFERENCE CODE:
There is a small problem, in fact,
Visual FoxPro 9.0 (and before) searches for the 32-bit Windows .dll function in:
1, User32.dll,
2, Gdi32.dll,
3, Kernel32.dll,
4, Advapi32.dll,
5, and Mpr.dll.
In VFP 9.0 (and before), usually, there is no Windows API function in 2 (or more) .dlls,
so this is not a big problem.
In VFP Advanced (x64), there are some Windows API functions in 2 (or more) .dlls.
For example,
there is a RegOpenKeyExA function in advapi32.dll,
and there is a RegOpenKeyExA function in kernel32.dll.
Usually, we want to call the RegOpenKeyExA function in advapi32.dll, not in kernel32.dll.
So VFP Advanced (x64) has changed it to:
Visual FoxPro Advanced searches for the 64-bit Windows .dll function in:
1, Advapi32.dll,
2, User32.dll,
3, Gdi32.dll,
4, Kernel32.dll,
5, and Mpr.dll.
3. REFERENCE WINDOWS APIS:
The following Windows API functions (Reg*) both in advapi32.dll and kernel32.dll:
RegCloseKey
RegCreateKeyExA
RegCreateKeyExW
RegDeleteKeyExA
RegDeleteKeyExW
RegDeleteTreeA
RegDeleteTreeW
RegDeleteValueA
RegDeleteValueW
RegDisablePredefinedCacheEx
RegEnumKeyExA
RegEnumKeyExW
RegEnumValueA
RegEnumValueW
RegFlushKey
RegGetKeySecurity
RegGetValueA
RegGetValueW
RegLoadKeyA
RegLoadKeyW
RegLoadMUIStringA
RegLoadMUIStringW
RegNotifyChangeKeyValue
RegOpenCurrentUser
RegOpenKeyExA
RegOpenKeyExW
RegOpenUserClassesRoot
RegQueryInfoKeyA
RegQueryInfoKeyW
RegQueryValueExA
RegQueryValueExW
RegRestoreKeyA
RegRestoreKeyW
RegSaveKeyExA
RegSaveKeyExW
RegSetKeySecurity
RegSetValueExA
RegSetValueExW
RegUnLoadKeyA
RegUnLoadKeyW
Usually, these Windows API functions in advapi32.dll will jump to the same name Windows API functions in kernel32.dll.
In other words, these Windows API functions in advapi32.dll is the same as these Windows API functions in kernel32.dll.
But, it is not always same.
For example,
the sprintf function in ntdll.dll is not the same as the sprintf function in msvcrt.dll.
In fact, the sprintf function in ntdll.dll is simpler, it does not supports some format-control strings such as %f.
4. OTHER:
For reference only, there is no guarantees.
Any questions or suggestions, please send me an email at ccb2000@163.com.
|