ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous Windows functions
  • Checks performed
  • Error management
  • Loading and unloading the DLL
  • Parameters that will be passed to the function of DLL
  • Passing a string to an API or retrieving a string from an API
  • Passing a structure containing a string to an API
  • Procedure called in CallBack
  • Miscellaneous
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Runs a function found in an external DLL. This function can be a function of Windows API. The functions accessible by CallDLL32 are the functions of the standard libraries of Windows (USER32, KERNEL32, GDI32, etc.).
The function can be identified by:
  • its name.
  • its number.
  • its address.
It is also possible to use a variable of type API Description. For APIs that use parameters of specific types or that are called multiple times in the same application, it is recommended to use an API Description variable directly (without using the CallDLL32 function).
Remarks:
  • This function is equivalent to API.
  • If the function to run contains QWORD parameters, you must use an API Description variable (Syntax 4).
CallDLL32("USER32", "SendMessageA", hWnd, wMsg, lParam1, lParam2)
Syntax

Running a function of an external DLL or a function of the Windows API identified by its name Hide the details

<Result> = CallDLL32(<DLL name> , <Function name> [, <Parameter 1> [... [, <Parameter N>]]])
<Result>: 4-byte integer in 32 bits, 8-byte integer in 64 bits
Result of execution of <Function name>. This result can be an error code. The type of this result depends on the function run. For more details, see the documentation about this function.
The function result will not be retrieved if its size exceeds the size of the integer defined for the platform.
<DLL name>: Character string
Name of library (DLL) containing the function to run.
<Function name>: Character string
Name of function to run. This function must be found in the specified DLL.
<Parameter 1>: Type corresponding to the parameter (optional)
First parameter that will be passed to the function. These parameters must have the same type as the parameters expected by the function. Can be used:
  • the "simple" types (see Remarks),
  • the structures (see Remarks),
  • a name of WLanguage procedure. This procedure will be called by the function of DLL (see Remarks).
<Parameter N>: Type corresponding to the parameter (optional)
Nth parameter that will be passed to the function. These parameters must have the same type as the parameters expected by the function. Can be used:
  • the "simple" types (see Remarks),
  • the structures (see Remarks),
  • a name of WLanguage procedure. This procedure will be called by the function of DLL (see Remarks).

Running a function of an external DLL or a function of Windows API identified by its number Hide the details

<Result> = CallDLL32(<DLL name> , <Function number> [, <Parameter 1> [... [, <Parameter N>]]])
<Result>: 4-byte integer in 32 bits, 8-byte integer in 64 bits
Result of execution of <Function name>. This result can be an error code. The type of this result depends on the function run. For more details, see the documentation about this function.
The function result will not be retrieved if its size exceeds the size of the integer defined for the platform.
<DLL name>: Character string
Name of library (DLL) containing the function to run.
<Function number>: Character string
Number of the function to run. This function must be found in the specified DLL.
<Parameter 1>: Type corresponding to the parameter
First parameter that will be passed to the function. These parameters must have the same type as the parameters expected by the function. Can be used:
  • the "simple" types (see Remarks),
  • the structures (see Remarks),
  • a name of WLanguage procedure. This procedure will be called by the function of DLL (see Remarks).
<Parameter N>: Type corresponding to the parameter
Nth parameter that will be passed to the function. These parameters must have the same type as the parameters expected by the function. Can be used:
  • the "simple" types (see Remarks),
  • the structures (see Remarks),
  • a name of WLanguage procedure. This procedure will be called by the function of DLL (see Remarks).

Running a function of an external DLL or a function of the Windows API identified by its address Hide the details

<Result> = CallDLL32(<Function address> [, <Parameter 1> [... [, <Parameter N>]]])
<Result>: 4-byte integer in 32 bits, 8-byte integer in 64 bits
Result of execution of <Function name>. This result can be an error code. The type of this result depends on the function run. For more details, see the documentation about this function.
The function result will not be retrieved if its size exceeds the size of the integer defined for the platform.
<Function address>: Integer
Address in memory of the function to run.
<Parameter 1>: Type corresponding to the parameter
First parameter that will be passed to the function. These parameters must have the same type as the parameters expected by the function. Can be used:
  • the "simple" types (see Remarks),
  • the structures (see Remarks),
  • a name of WLanguage procedure. This procedure will be called by the function of DLL (see Remarks).
<Parameter N>: Type corresponding to the parameter
Nth parameter that will be passed to the function. These parameters must have the same type as the parameters expected by the function. Can be used:
  • the "simple" types (see Remarks),
  • the structures (see Remarks),
  • a name of WLanguage procedure. This procedure will be called by the function of DLL (see Remarks).
Remarks

Checks performed

  • CallDLL32 is protected against "General Protection Faults" in the function called. Nevertheless, a WLanguage error is triggered if this type of error occurs.
  • For the functions following the PASCAL call prototype (especially the functions of the Windows API), a simple check on the number of parameters passed to the function is performed. A WLanguage error occurs in case of discrepancy.

Error management

When running functions of the Windows API, if the result returned corresponds to an error, use ErrorInfo (associated with the errSystemCode or errSystemMessage constant) to find out the error details.

Loading and unloading the DLL

CallDLL32 automatically loads the DLL if necessary, then it unloads it (if it was loaded). This mechanism can be quite slow, except for the system DLLs (KERNEL, USER, GDI).
To optimize the execution speed, we advise you to load the DLL once with LoadDLL and to unload it with FreeDLL when it is no longer used.

Parameters that will be passed to the function of DLL

These parameters must have the same type as the parameters expected by the function.
The available types are as follows:
  • The "simple" types (integer, real and boolean). Using another WLanguage type triggers a WLanguage error.
    If the function to run expects a pointer or a Windows handle, use a system integer.
    If the function to run expects an address, use the & operator.
  • The "string" types.
  • The structure types.
  • A name of WLanguage procedure. This procedure will be called by the function of the DLL (see the paragraph below).
    The parameters depend on the function run. For more details, see the documentation about this function.

Passing a string to an API or retrieving a string from an API

  1. In input parameter, use the string type. For example:
    sChaîne est une chaîne
    AppelDll32(<DLL>, <Fonction>, sChaîne)
  2. In output parameter, the C language cannot easily manage the dynamic strings. Therefore, you must:
    • define a maximum size, with the "String of" type. For example:
      sChaîne est une chaîne sur 100
      AppelDLL32(<DLL>, <Fonction>, sChaîne)
      // dans Methode en C:
      // STRNCPY(PointeurEnC, "Test", 100)
    • retrieve the addresses of strings in C (however, in this case, the code section in C must "preserve" the strings returned), then transfer the string into a string variable with StringRetrieve. For example:
      nAdresseChaîne est un entier système
      AppelDLL32(<DLL>, <Fonction>, &nAdresseChaîne)
      sChaîne est une chaîne
      sChaîne = ChaîneRécupère(nAdresseChaîne, crAdresseASCIIZ)
      // dans Méthode en C: *PointeurEnC = "Test"
  3. In return value, retrieve the addresses of strings in C (however, in this case, the code section in C must "preserve" the strings returned), then transfer the string into a string variable with StringRetrieve. For example:
    nAdresseChaîne est un entier système
    nAdresseChaîne = AppelDLL32(<DLL>, <Fonction>)
    sChaîne est une chaîne
    sChaîne = ChaîneRécupère(nAdresseChaîne, crAdresseASCIIZ)
    // dans Méthode en C: Return PointeurEnC

Passing a structure containing a string to an API

  1. In input, the following code must be used:
    Struct est une structure
    sChaîne est une chaîne
    FIN
    UneStruct est une Struct
    AppelDLL32(<DLL>, <Fonction>, &UneStruct)
  2. In output, the C language does not easily manage the dynamic strings. Therefore, you must:
    • define a maximum size and perform a copy into the WLanguage memory. For example:
      sChaîne est une chaîne sur 100
      Struct est une structure
      aChaîne est un entier
      FIN
      UneStruct est une Struct
      UneStruct:aChaîne = &sChaîne
      AppelDLL32(<DLL>, <Fonction>, &UneStruct)
      // dans Methode en C:
      // STRNCPY(StructEnC->PointeurEnC, "Test", 100)
    • retrieve the address of strings in C (however, in this case, the code section in C must "preserve " the strings returned). For example:
      sChaîne est une chaîne
      Struct est une structure
      aChaîne est un entier
      FIN
      UneStruct est une Struct
      AppelDLL32(<DLL>, <Fonction>, &UneStruct)
      sChaîne = ChaîneRécupère(UneStruct:aChaîne, crAdresseASCIIZ)
      // dans Methode en C: StructEnC->PointeurEnC = "Test"

Procedure called in CallBack

Some Windows API functions require the address of a "CallBack" procedure as a parameter: this procedure will be called by the API function.
For example: the EnumWindows API enumerates all open Windows windows on a workstation.. This function expects the address of a procedure as a parameter: this procedure will be called up for each window found.
Note: CallBack procedures can be used in both 32-bit and 64-bit versions..
To use a callback procedure in WLanguage:
1. Create the callback procedure in your project.
To retrieve the parameters, you must exactly describe the parameters expected by the "CallBack" function. Otherwise, "general protection faults" may occur.
PROCEDURE <Nom de la procédure> (<Param1> est [un] <Type1>,<Param2> est [un] <Type2>)
Remarks:
  • The types must correspond to the ones described in the documentation of the API.
  • The type of the "CallBack" function of the DLL must be "stdcall".
  • The parameters must necessarily be passed by value. To retrieve a parameter by reference:
    1. Use an integer.
    2. With Transfer, retrieve or assign the real value.
2. Modify the call to the function accordingly. Use the following syntax:
AppelDLL32(<Nom de la DLL>, <Nom de la fonction>, <Nom de la procédure CallBack>)
For more details, see the full example.

Miscellaneous

  • API and CallDLL32 do not lock the other threads.
  • If the API function called modifies the system regional settings, the previous regional settings are restored.
APIConfigure is used to configure the default behavior of these functions.
Note: up to version 100045:
  • API and CallDLL32 lock the other threads.
  • If the API function called modifies the system regional settings (languages, decimal places, etc.), the previous regional settings are not restored.
Related Examples:
Strings with APIs Unit examples (WINDEV): Strings with APIs
[ + ] Using strings with APIs.
The following functions are used:
- StringRetrieve
- Transfer
WD SystemAPIs Training (WINDEV): WD SystemAPIs
[ + ] This example presents the use of the Windows APIs. Several WLanguage functions are used to perform the following operations:

- Hide the system buttons of an MDI child window
- Enumerate the opened windows
- Retrieve/Modify the time of a double click
- Retrieve the idle time on the computer
- Empty the recycle bin (by using or not an "API descriptor" variable)
- Change the screen background
- Modify the caret (input cursor) of an edit control
- Share a directory
- Delete a share

These functions use the Windows APIs. See the help window for more details.
WD Screen Saver Training (WINDEV): WD Screen Saver
[ + ] This example illustrates the creation of a screen saver with the WLanguage functions.
The following topics are presented in this example:
1/ the periodic call to a procedure ("timers")
2/ the management of Windows events
3/ the system functions (call to Windows APIs)
To use the screen saver:
- Rename the executable (.EXE) to.SCR
- Copy the file to the directory of Windows (Ex: C:\WINDOWS)
- Open the window for the display properties of the desktop
- Choose the "Screen Saver" tab
- Select the screen saver generated by WINDEV
WD DirectX Training (WINDEV): WD DirectX
[ + ] DirectX is a set of libraries (or APIs) intended for programming multimedia applications.
This example includes an internal component allowing you to use DirectX 9.0 in your WINDEV applications.
All the APIs and interfaces of DirectX 9 have been implemented.
Component: wd300vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3763-windev-desenvolvendo-dll-assembler-net-32-64-usando/read.awp
Boller
01 Jun. 2021
Alterar Papel de Parede
PROCEDURE Wallpaper()

// Alterando o Papel de parede do Windows
bAlterado is boolean = False
fMakeDir("C:\Temp\")
fCopyFile("saw.apt","sawarning.jpg")
WRegFondEcran is string = "C:\Temp\sawarning.jpg"
fCopyFile("sawarning.jpg","C:\Temp\sawarning.jpg")
WChemin is string = "HKEY_CURRENT_USER\Control Panel\Desktop"
IF RegistrySetValue (WChemin, "Wallpaper", WRegFondEcran) = False
Error("Error image")
bAlterado = False
ELSE
bAlterado = True
uAction is int
uParam is int
lpvParam is string ASCIIZ on 255
uAction = 20
uParam = 0
lpvParam = WRegFondEcran
CallDLL32("user32", "SystemParametersInfoA", uAction, uParam,&lpvParam, 0)
END

RESULT bAlterado
BOLLER
02 Apr. 2019
Video CallDll32
https://youtu.be/F72RFUHyyMQ
amarildo
16 Dec. 2018

Last update: 09/21/2024

Send a report | Local help