Lugaru's Epsilon
Programmer's
Editor 14.04

Context:
Epsilon User's Manual and Reference
   Primitives and EEL Subroutines
      . . .
      File Primitives
         File Reading Primitives
         File Writing Primitives
         Line Translation Primitives
         . . .
         Tagging Internals
      Operating System Primitives
         . . .
         Window System Primitives
         Timing
         Calling Windows DLLs
         Running a Process
      Control Primitives
         Control Flow
         Character Types
         Examining Strings
         . . .
         Help Subroutines
      . . .

Previous   Up    Next
Timing  Primitives and EEL Subroutines   Running a Process


Epsilon User's Manual and Reference > Primitives and EEL Subroutines > Operating System Primitives >

Calling Windows DLLs

int call_dll(char *dll_name, char *func_name,
             char *ftype, char *args, ...)

The call_dll( ) primitive calls a function in a Windows DLL. The 32-bit version of Epsilon can only call 32-bit DLLs, and the 64-bit version can only call 64-bit DLLs. The dll_name parameter specifies the DLL file name. The func_name parameter specifies the name of the particular function you want to call.

The ftype parameter specifies the routine's calling convention. The character C specifies the C calling convention, while P specifies the Pascal calling convention. Most Windows DLLs use the Pascal calling convention, but any function that accepts a variable number of parameters must use the C calling convention.

The args parameter specifies the type of each remaining parameter. Each letter in args specifies the type of one parameter, according to the following table.

 Character  Description  
 L  int  INT, UINT, HWND, most other handles
 I  int32  32-bit integer
 S  far char *  LPSTR
 P  far void *  LPVOID
 R  far void **  LPVOID *

The codes L, S, P, and R represent 64-bit parameters (but 32-bit when calling 32-bit DLLs). The I character always represents a 32-bit parameter.

S represents a null-terminated string being sent to the DLL. P is passed similarly, but Epsilon will not check the string for null termination. It's useful when the string is an output parameter of the DLL, and may not be null-terminated before the call, or when passing structure pointers to a DLL.

R indicates that a DLL function returns a pointer by reference. Epsilon will pass the pointer you supply (if any) and retrieve the result. Use this for DLL functions that require a pointer to a pointer, and pass the address of any EEL variable whose type is "pointer to ..." (other than "pointer to function").

Here's an example, using call_dll( ) to determine the main Windows directory:

#define GetWindowsDirectory(dir, size)  \
    (call_dll("kernel32.dll", "GetWindowsDirectoryW", \
              "p", "pi", dir, size))

    char dir[FNAMELEN];

    GetWindowsDirectory(dir, FNAMELEN);
    say("The Windows directory is %s", dir);

After you call a function in a DLL, Epsilon keeps the DLL loaded to make future calls fast. You can unload a DLL loaded by call_dll( ) by including just the name of the DLL, and omitting the name of any function or parameters. For example, call_dll("extras.dll"); unloads a DLL named extras.dll.

char *make_pointer(int value)

The make_pointer( ) primitive can be useful when interacting with system DLLs. It takes a machine address as a number, and returns an EEL pointer that may be used to access memory at that address. No error checking will be done on the validity of the pointer.



Previous   Up    Next
Timing  Primitives and EEL Subroutines   Running a Process


Lugaru Epsilon Programmer's Editor 14.04 manual. Copyright (C) 1984, 2021 by Lugaru Software Ltd. All rights reserved.