ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Managing external languages / C language
  • Overview
  • Implementation
  • 1. Including the files of the C interface of WINDEV
  • 2. Including the HFSQL declarations
  • Declaration and initialization
  • 1. Declaring the HFSQL 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/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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 project (Visual C++ 6 format), available in the "External Languages\EN\C" subdirectory of the WINDEV installation directory.
  • the BC5.0.IDE project (Borland C 5 format), available in the "External Languages\EN\C" subdirectory of the WINDEV installation directory.
Remark: other modes are available for programming in external language. For more details, see The programming modes of the external languages
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" // HFSQL 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 HFSQL 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 (provided 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 HFSQL context and the working buffers of each file:

If the application must manage data files, an HFSQL 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 HFSQL 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 by calling nWDInit, at the beginning of the WinMain procedure as follows:
if (nWDInit(FALSE)!=WDERROR_OK) ... // manage the error case
3. Initializing HFSQL
If your application is calling a database, the access to HFSQL must be prepared now. 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 allows you to call the data files. Once this analysis has been opened with HOpenAnalysis, simply 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 external language
To find out the parameters and the return values of a WLanguage function, see the online help or the documentation about WLanguage.
You can use nWDExecute to call a WLanguage procedure from the external interface. 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 application")==0 ) nWDExecute("CLOSE()"); // Exit
Code of "File .. Exit" of the WINDEV "Menu" window (WLanguage):
WDKey="Exit 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 version required
  • Version 9
Comments
Click [Add] to post a comment

Last update: 09/06/2023

Send a report | Local help