AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de Windows / Funciones varias de Windows
  • 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
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
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)
Sintaxis

Running a function of an external DLL or a function of the Windows API identified by its name Ocultar los detalles

<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 Ocultar los detalles

<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 Ocultar los detalles

<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>: entier
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).
Observaciones

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 entire system.
    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:
    sString is string
    CallDll32(<DLL>, <Function>, sString)
  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:
      sString is string of 100
      CallDLL32(<DLL>, <Function>, sString)
      // in Method in C:
      // STRNCPY(PointerInC, "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:
      nStringAddress is system int
      CallDLL32(<DLL>, <Function>, &nStringAddress)
      sString is string
      sString = StringRetrieve(nStringAddress, srASCIIZAddress)
      // in C Method: *PointerInC = "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:
    nStringAddress is system int
    nStringAddress = CallDLL32(<DLL>, <Function>)
    sString is string
    sString = StringRetrieve(nStringAddress, srASCIIZAddress)
    // in C Method: Return PointeurEnC

Passing a structure containing a string to an API

  1. In input, the following code must be used:
    Struct is structure
    sString is string
    END
    AStruct is Struct
    CallDLL32(<DLL>, <Function>, &AStruct)
  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:
      sString is string of 100
      Struct is structure
      aString is int
      END
      AStruct is Struct
      AStruct:aString = &sString
      CallDLL32(<DLL>, <Function>, &AStruct)
      // in Method in C:
      // STRNCPY(CStruct->PointerInC, "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:
      sString is string
      Struct is structure
      aString is int
      END
      AStruct is Struct
      CallDLL32(<DLL>, <Function>, &AStruct)
      sString = StringRetrieve(AStruct:aString, srASCIIZAddress)
      // in Method in C: StructInC->PointerInC = "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 Reminder 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
This procedure can be:
  • a comprehensive project procedure.
  • Novedad versión 2025
    a method of the current object.
    Note: This feature is only available from version 2025 Update 1.
To retrieve the parameters, you must exactly describe the parameters expected by the "CallBack" function. Otherwise, "general protection faults" may occur.
PROCEDURE <Procedure name> (<Param1> is <Type1>,<Param2> is <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:
CallDLL32(<DLL Name>, <Function Name>, &<Name of CallBack Procedure>)
For more details, see 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.
Componente: wd300vm.dll
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Exemplo
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3763-windev-desenvolvendo-dll-assembler-net-32-64-usando/read.awp
Boller
01 06 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 04 2019
Video CallDll32
https://youtu.be/F72RFUHyyMQ
amarildo
16 12 2018

Última modificación: 25/03/2025

Señalar un error o enviar una sugerencia | Ayuda local