PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Implementation
  • 1. Including the files of the C interface of WINDEV
  • 2. Including the HyperFileSQL declarations
  • Declaration and initialization
  • 1. Declaring the HyperFileSQL context and the working buffers of each file:
  • Running WINDEV codes from the external language
  • 1. Initialization code of the WINDEV project
  • 2. Calling a WLanguage code
  • 3. Retrieving the events triggered in the WINDEV windows
  • Ending the application
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview
We are going to call the elements developed in WINDEV (project, windows, ... analysis) from the C language. This system is based on the use of the functions declared in the .h, .c and .cpp files of WINDEV. The WLanguage code used from the external language will be dynamically compiled and run during its call.
This mode is illustrated in:
  • the VC60.dsp (in Visual C++ 6 format) supplied in the "ExternalLanguages\C" sub-directory of the setup directory of WINDEV.
  • the BC5.0.IDE project (in Borland C 5 format) supplied in the "ExternalLanguages\C" sub-directory of the setup directory of WINDEV.
Note: other modes are available for programming in external language. See The programming modes of the external languages for more details
Implementation

1. Including the files of the C interface of WINDEV

If you are using a database in your application, the first step consists in generating your analysis. In the description of this analysis, specify the programming language used as well as the directory that will contain the source files.
Via the generation, a program skeleton is generated in the selected external language (C for example). This operation will also create the .h file (see below) required to use your data files.
The following files must be included in a C project in order to call the C interface of WINDEV in this second method:
The two following lines must be found in the code of the main .c file of your C project:
# include "WDExtern.h" // WINDEV language and objects
# include "HFContext.h" // HyperFileSQL database
These lines allow you to retrieve the minimum declarations required to use the external interface. You will notice that the .h files that describe the structure of the files will be automatically generated by WINDEV when generating the analysis.

2. Including the HyperFileSQL declarations

An inclusion (#include) must be added for each data file declared in the analysis of the WINDEV project. The declarations of data files are included in the file whose extension is.h (this file replaces the.wdr created with the earlier WINDEV version).
For example, in the Vc60.dsp project (supplied with WINDEV in the "ExternalLanguages" directory), the following line is used to manage the City and State files:
#include "WD External language.h"
Declaration and initialization

1. Declaring the HyperFileSQL context and the working buffers of each file:

If the application must manage data files, a HyperFileSQL working context must be declared as well as a buffer for each data file.
These declarations are performed in the Vc60.dsp project via the following lines:
CHFContext gclHF; // Management of the HyperFileSQL context
StCITY gstCity; // HF buffer of City file
StSTATE gstState;       // HF buffer of State file
2. Initializing the WINDEV DLLs
The first step before using the elements developed in WINDEV is to load the WINDEV DLLs in memory and to initialize them.
These operations are performed via the call to nWDInit, at the beginning of your WinMain procedure as follows:
if (nWDInit(FALSE)!=WDERROR_OK) ... // manage the error case
3. Initializing HyperFileSQL
If your application is calling a database, the access to HyperFileSQL must now be prepared. The test below is used to check whether this initialization is performed properly:
IHFContext * pIHF;
if (!((nWDGetHFContext((void**)&pIHF)==WDERROR_OK) &&
(gclHF.bInit(pIHF))))
{
// manage the error case
}
4. Loading the WINDEV library (WDL)
The WINDEV library (.WDL extension) contains all the project elements (windows, reports, classes, queries, analysis, ...). Therefore, it must be loaded in memory in order for its components to be called.
The load operation is performed by nWDOpenWDL as follows:
if (nWDOpenWDL(szWDL)!=WDERROR_OK)
{  
// Library not found
}
5. Opening the project analysis and associating buffers with the data files
Opening the analysis enables you to call the data files. Once this analysis has been opened by /HOpenAnalysis, all you have to do is associate the working buffers with the files described in this analysis:
// Open the analysis (WDD contained in the WDL)
if (!gclHF.HOpenAnalysis(szAnalysis,szPassword))
{
// Error opening the analysis
}
// Buffer <-> file association
gclHF.bAssociate("city",&gstCity,sizeof(gstCity));
gclHF.bAssociate("state",&gstState,sizeof(gstState));
Running WINDEV codes from the external language

1. Initialization code of the WINDEV project

This code is used to start the WINDEV project by declaring the global variables for example. It is run from the external language by nWDInitProject. For example:
if (nWDInitProject("")==WDERROR_INIT)
{
// Error initializing the project
}

2. Calling a WLanguage code

All the WLanguage functions can be called from the external language. The behavior of these WLanguage functions as well as the returned values are identical whether they are called:
  • from WINDEV or
  • from the interface of the external language
To find out the parameters and the return values of a WLanguage function, see the online help or the documentation about WLanguage.
The call to a WLanguage procedure from the external interface is performed by nWDExecute. For example:
nWDExecute("OPEN(\"menu.wdw\")"); // Open the WINDEV window
You will notice that the parameter expected by nWDExecute being a C character string containing the WLanguage code to run, you must respect the syntax of C strings (the \ characters must be doubled, the quotes must be preceded by the control character \ ... etc). This enables you to format this string with control characters such as %s, %l ... like the printf function of C.
Furthermore, as for the WLanguage coded in WINDEV, this string is not case sensitive (uppercase/lowercase characters). Therefore, the "Info" command can also be written as "INFO".

3. Retrieving the events triggered in the WINDEV windows

The input in the WINDEV windows requires to retrieve the events triggered in these windows.
To retrieve the user events (click on a menu, on a button, ...), you must implement a system based on a 'callback' function in your C program. This function will be called automatically by your WINDEV window for each user action.
To find out the type of action performed by the user, you have the ability to use a character string variable (in WLanguage) named 'WDKey'. This variable will be used in your WLanguage code to signal to the C program which button has been pressed for example. This string has no size limit and it can contain the detailed statements that will be retrieved from your C code.
Example: C code
// Open the first application window
// Define the procedure that manages the WINDEV window
nWDSetCallbackNext(CallBackMenu,0);
// Open the WINDEV window
nWDExecute("OPEN(\"menu.wdw\")");
[...]
C procedure used as callback for the window:
void CallBackMenu(DWORD dwUserParam,LPCTSTR pszCodeAction)
{
// pszCodeAction contains the sequence of shortcuts
// that are used to select the menu choice  
if( strcmp(pszCodeAction,"Exit from the application")==0 ) nWDExecute("CLOSE()"); // Exit
Code of "File .. Exit" of the WINDEV "Menu" window (WLanguage):
WDKey="Exit from the application"
nWDSetCallbackNext allows you to define the procedure associated with the next window that will be opened. The call to nWDExecute to perform then opening of this window ens the link between the "Menu" window and the "CallBackMenu" callback.
When the user clicks "File..Exit", WDKey will be returned in the "pszCodeAction" parameter to the "CallBackMenu" callback that can be tested in the C code in order to perform the next action.
Note: The WDKey variable being a character string, its content can be a detailed description of the action to perform. For example, "Close the application".
Ending the application
To end the use of the external interface, all you have to do is call WDTerm that expects no parameter. For example:
WDTerm();
Minimum required version
  • Version 9
Comments
Click [Add] to post a comment