Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a VFP FLL with Visual C(++)

API Functions

How to create a VFP FLL with Visual C(++)

by  rob444  Posted    (Edited  )
An FLL (C DLL) accesses the VFP API.
The VFP API is designed to let developers extend the abilities of Visual FoxPro which can be done by FLLs (or ActiveX).
The pro of using a FLL is that you can compile it into your VFP program, it doesnÆt has to be registered (ActiveX has to be registered)
FLLs are written in Visual C(++) which results in fast and small code..

In Visual C++ 6
Select the File->New menu
In the New dialog
Select the type of project (Win32 Dynamic-Link Library), enter nameofproject and location.
Select the simple DLL project option
A .dsw file is created (developer studio workspace)
Additional files are generated and added (stdafx.cpp, nameofproject.cpp and stdafx.h)
Select the ôSet Active Configurationö option from the Build system menu.
Select the Win32 Release item and click OK
Specify the multi-thread runtime lib for linking. (for the release config this is the msvcrtxx.dll, for the debug config this is the msvcrtdxx.dll)
Select the Settings menu option from the Project System menu. This brings up the Project Settings dialog. Select the C/C++ page of the page frame provided on the right and select the Code Generation item from the Category combo box, the Multithreaded DLL item from the Use runtime library combo box, and the __fastcall item from the Calling convention combo box.
Change the output file extention, select the Link page provided in the Project Settings dialog, select the General item from the Category combo box. Use the Output file name text box to replace ".dll" with ".fll".
Add winapims.lib to the front of the list of object/library modules.
The pro_ext.h (always in the .cpp file as an include) and winapims.lib files are located in the API subdirectory of VFP Samples
Select Build > Build nameofproject.fll from the menu and if there are no errors and no warnings reported the FLL was successfully built in the release directory


In Visual C++ 7/8
New Project dialog
Select the type of project (Win32 Project Template) and enter name.
Select Application Settings in the left pane and select the DLL option for Application type
A .sln file is created (solution project)
Additional files are generated and added (stdafx.cpp, nameofproject.cpp and stdafx.h)
Select Project Properties (right-click on the projectÆs Solution Explorer / selecting Properties from the Context menu)
Specify the multi-thread runtime lib for linking. (for the release config this is the msvcrtxx.dll, for the debug config this is the msvcrtdxx.dll)
Select the Code Generation node under Configuration Properties C/C++ in the Property Pages of the project. Then, select the Multi-threaded DLL (/MD) item from the Runtime Library combo box. (/MD is the compiler switch used.)
Switch to the Advanced node, set the FLLÆs calling convention to __fastcall by selecting the appropriate item from the Calling Convention combo box.
Change the output file extention, you do this by clicking into the Linker node of the Configuration Properties selecting the General page. In the Output File combo box of the right pane, change the extension by typing ".fll".
Click on the Input node underneath the Linker Configuration Properties in the Property Pages, select the Additional Dependencies row in the right pane. Click on the ellipsis button, the Additional Dependencies dialog opens. Type in the name of the library, winapims.lib, and click on the OK button to save the change.
The pro_ext.h (always in the .cpp file as an include) and winapims.lib files are located in the API subdirectory of VFP Samples.
Select Build > Build nameoftheproject option from the menu. Visual C++ builds the project. If there are no errors and no warnings, the FLL was successfully built in the release directory


An example of sourcecode for a FLL ( a .cpp file )
Code:
	#include <pro_ext.h>
	
	#define C_HELLOWORLD "Hello World!"
	
	void MyTest()
	{
	    _RetChar(C_HELLOWORLD);
	}
	
	void MyTest2()
	{
	    HWND hWndMain = _WhToHwnd(_WMainWindow());
	    char szCaption[128];
	
	    GetWindowText(hWndMain,szCaption,128);
	    MessageBox(
	        hWndMain,
	        C_HELLOWORLD,
	        szCaption,
	        MB_ICONINFORMATION);
	
	    _RetChar(C_HELLOWORLD);
	}
	
	FoxInfo myFoxInfo[] = 
	{
	    {"TEST",  (FPFI) MyTest,  0, ""},
	    {"TEST2", (FPFI) MyTest2, 0, ""}
	};
	
	
	#ifdef __cplusplus
	extern "C"
	#endif
	FoxTable _FoxTable = {
	(FoxTable *)0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
	};

More info on how to return values and info about FoxTable and FoxInfo structures is available in the VFP helpfile under API -> accessing VFP API
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top