Another hurdle I just needed to fix to try this:
Create a new VS solution with the project template "DLL (Dynamic Link Library) with exports", the difference to the normal DLL project template is that "with exports" creates a header file "YourDLL.h" including the declarations of a sample function for external usage. The actual code implementations of a sample function and something else are in turn in a separate "YourDLL.cpp" code file.
And you can almost go straight to building this solution for a test and get a DLL working for VFP, too. You want to change the target platform to x86, not x64, otherwise no chance to use this from VFP. Maybe already change from Debug to Release, too, but not that important. What's far less obvious and thus most important to tell here is, that the way the declarations are written in the sample header file, VFP won't find the entry point to a function, for example for the sample DLL function fnYourDll() of the project template.
There's just a slight fix necessary, change the header file here
Code:
VS DLL with exports template header file[/ignore]]YOURDLL_API int fnYourDll(void);
and prefix it:
Code:
fixed for DLL entry point visibility to VFP[/ignore]][highlight #FCE94F]extern "C"[/highlight] YOURDLL_API int fnYourDll(void);
If you now build you can use the DLL in VFP with
Code:
*CD into the Visual Studio output path to Debug or Release folder with YourDll.DLL
DECLARE INTEGER fnYourDll in YourDll.dll
? fnYourDll() && prints 0
Watch out that in general, not just for VS C++ DLLs DECLARE is case sensitive.
To extend this, start with such a declaration in the header. A light bulb icon will appear as VS detects this declaration has no definition yet and offers to copy this over into the cpp file to match the declaration. Why at all? Ask the c++ inventors, I guess all these declarations in a header file will give a short overview of that functions are available, nowadays you could just collapse a code file to only show the declaration head of the definition to have that same overview. Anyway, that's the C++ world and this will also be found in code you may find as implementation of string function X or encryption function Y or whatever you'd like to have in VFP. It's also an extensibility vector of VFP.
Bye, Olaf.
Olaf Doschke Software Engineering